How to get URL parameters in a Django view?

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)

{{ request.resolver_match.kwargs.argument }}

for function arguments passed to the view as:

def myview(request, argument):

Tested on Django 1.9.


{{request.GET.param1}} in the template. (Using RequestContext)

request.GET.get('param1', None) in the view.

Tags:

Django