Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7939655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:10:07+00:00 2026-06-03T23:10:07+00:00

I have a Django project where I have a search page which takes input

  • 0

I have a Django project where I have a search page which takes input through a POST and redirect to /search/<search string>/ and this page renders the result. The percentage sign (%) is used as a wildcard in the search (tes%er returns testuser, tester, etc and the url looks like this then: example.com/search/tes%25er/) and everything works fine with the Django development server. If I manually write tes%er in the url it changes to tes%25er automatically.

Now I’m deploying on an Apache server with mod_wsgi and when my search page redirects to example.com/search/tes%er/ I get the server error: Bad Request. Your browser sent a request that this server could not understand.. If I manually add ’25’ to the url, like the encoded % sign so it looks like the development server it works fine.

Is there a way for Apache to automatically escape the %-sign and create a url that works, understand % unescaped or do I need to do ugly hacks in my search page that builds the url? (I’d rather not do ugly hacks like this cause then the users can’t manually add % to the url and get it to work).

Edit: The code that sends the query from the search page to the search url.

if form.is_valid():
    if 'search_user' in request.POST:
        q = request.POST['search_user']
        return redirect('/search/'+q)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T23:10:09+00:00Added an answer on June 3, 2026 at 11:10 pm

    As Ignacio already suggested, you should not redirect to an invalid url. So to answer your question:

    you can (or perhaps its better to say ‘should’) not ask your Apache server to escape your url. The reason you escape your URL is because some characters have another meaning. For example, take a querystring:

    somedomain.com/?key=value

    If we would want to use a ? or a = in your value you would have a problem because your server would think that you are using operators of your querystring.

    The same for the %-symbol. When your apache server sees a %-symbol he thinks he will find an enconded and will try to decode it. If your querystring is %20, apache will translate this to a space, while you meant “wildcard20”.

    In summary: apache decodes your string, so you dont want him to encode it.

    But this does not solve your problem. You can solve your problem by changing your code into the following:

    from urllib import urlencode
    if form.is_valid():
        if 'search_user' in request.POST:
            q = request.POST['search_user']
            return redirect('/search/?q='+urlencode(q))
    

    In case you wonder: what if my user would type /search/?q=%; in that case he’ld have a problem for he has typed an invalid address.

    Hope this helps :-).

    Wout

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a django project which is laid out like this... myproject apps media
I have a Django project in which multiple processes are accessing the backend mysql
I have a Django project. Given a url, how can I know which view
I have a Django-project which was running fine, until I made some changes I
I have Django project on Dreamhost server which has several views that returns Json
I have a django project in which a user will type in a url
folks, I have the directory structure like this: webapps |-- static_media |-- django |---project
I have a django project in which database values need to be updated fairly
I have a Django project, that has a Address model. This is used in
I have Django project which uses postgresql 9. I installed psycopg2 and when I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.