I am using django 1.2 and going from one view to another using the urlresolvers reverse method.
url = reverse(viewOne)
and I want to pass a get parameter, for example
name = 'joe'
so that in the viewOne if I do
def viewOne(request): request.GET['name']
I will get
joe
how do I do that ?
the reverse function allows to retrieve url details from url's.py file through the name value provided there. This is the major use of reverse function in Django. The redirect variable is the variable here which will have the reversed value. So the reversed url value will be placed here.
We can access the query params from the request in Django from the GET attribute of the request. To get the first or only value in a parameter simply use the get() method. To get the list of all values in a parameter use getlist() method.
reverse_lazy is used for resolving Django URL names into URL paths. The resolution is not seen by the end user client as all of this work occurs within the Django application code and framework code.
GET parameters have nothing to do with the URL as returned by reverse
. Just add it on at the end:
url = "%s?name=joe" % reverse(viewOne)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With