I am currently defining regular expressions in order to capture parameters in a URL, as described in the tutorial. How do I access parameters from the URL as part the HttpRequest object?
My HttpRequest.GET currently returns an empty QueryDict object.
I’d like to learn how to do this without a library, so I can get to know Django better.
When a URL is like
domain/search/?q=haha, you would userequest.GET.get('q', '').qis the parameter you want, and''is the default value ifqisn’t found.However, if you are instead just configuring your
URLconf**, then your captures from theregexare passed to the function as arguments (or named arguments).Such as:
Then in your
views.pyyou would have