How to get URL parameters in a Django view?
Suppose I have a url that has php style parameters, that is:
http://example.com/blah?param1=val1¶m2=val2
and I want to place the开发者_开发技巧ir values into the generated HTML of the template.
How do I achieve this?
{{request.GET.param1}}
in the template. (Using RequestContext)
request.GET.get('param1', None)
in the view.
{{ request.resolver_match.kwargs.argument }}
for function arguments passed to the view as:
def myview(request, argument):
Tested on Django 1.9.
Suppose you have GET Method like this -
http://djangopmt.localhost/tasks/?project=1&status=3&priority=High&search=StudyGyaan.com
We can get the URL Parameters like this in Django Template -
{{request.GET.project}}
{{request.GET.status}}
{{request.GET.priority}}
{{request.GET.search}}
And if you want to get URL parameter in Django Views then you can get it like this -
request.GET.get('project', None)
request.GET.get('status', None)
request.GET.get('priority', None)
request.GET.get('search', None)
精彩评论