Reputation: 1133
I want to route the following uri to a view;
localhost:8000/?tag=Python
to
def index_tag_query(request, tag=None):
in my url conf, I've tried the following regex patterns but none seem to be capturing the request even though the regex looks good;
url(r'^\?tag=(?P<tag>\w+)/$', 'links.views.index_tag_query'),
url(r'^\/?\?tag=(?P<tag>\w+)/$', 'links.views.index_tag_query'),
url(r'^\/?\?tag=(?P<tag>.*)/$', 'links.views.index_tag_query'),
What gives?
Upvotes: 5
Views: 10156
Reputation: 53971
You can't parse GET parameters from your URLconf. For a better explanation then I can give, check out this question (2nd answer): Capturing url parameters in request.GET
Basically, the urlconf parses and routes the URL to a view, passing any GET parameters to the view. You deal with these GET parameters in the view itself
urls.py
url(r^somepath/$', 'links.views.index_tag_query')
views.py
def index_tag_query(request):
tag = request.GET.get('tag', None)
if tag == "Python":
...
Upvotes: 8