[Answered ]-How to remove the ?q= from the url in Django

2👍

Correct urls.py

urlpatterns = patterns('',
     url(r'^$', 'home', name='home'),
     url(r'^(?P<search_term>[A-Za-z0-9\-]+)$', 'home', name='query'),  # without =q
👤Vadym

0👍

The ? in the URL separates the path which Django matches against URL patterns from the query parameters, which are read from the request object after a route is selected and activated.

That is, your second URL pattern will never match any URL which has a literal ? in it.

Your second URL pattern should match

[domain name]/q=[search_term]

but won’t match

[domain name]/?q=[search_term]

0👍

This is not possible with GET requests. You need to use a post with a variable in order for this to work

👤csling

Leave a comment