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.
For situations where you only have the
request
object you can userequest.parser_context['kwargs']['your_param']
I'd like to add some option of myself, here. Someone would wonder how to set path in urls.py, such as
so that we could invoke query.
The fact is that it is NOT necessary to set such a route in urls.py. What you need to set is just the route in urls.py
and when you input http://servername:port/domain/search/?q=CA. The query part '?q=CA' will be automatically reserved in the hash table which you can reference though
Here is an example (views.py)
In addition, when you write query string in Url
Do not wrap query string in quotes e.g
Using GET
Using POST