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
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
- [Answered ]-Get the username from user ID in django models
- [Answered ]-If / else in Django View
- [Answered ]-Limiting the number of displayed instances of a model in Django Admin
Source:stackexchange.com