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?
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":
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With