Sometimes, we want to get query string parameters with Python Django.
In this article, we’ll look at how to get query string parameters with Python Django.
How to get query string parameters with Python Django?
To get query string parameters with Python Django, we can use the request.GET property.
For instance, we write
def get_item(request):
id = int(request.GET.get('id'))
type = request.GET.get('type', 'default')
in the get_item view function to get the id query parameter with
id = int(request.GET.get('id'))
And we get the type query parameter with
type = request.GET.get('type', 'default')
The type query parameter has default value 'default' if it doesn’t exist.
Conclusion
To get query string parameters with Python Django, we can use the request.GET property.