Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i pass GET parameters using django urlresolvers reverse

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 ?

like image 200
yossi Avatar asked Mar 06 '12 14:03

yossi


People also ask

What does reverse () do in Django?

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.

How do I get all query parameters in Django?

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.

What does reverse lazy do in Django?

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.


1 Answers

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) 
like image 50
Daniel Roseman Avatar answered Sep 29 '22 06:09

Daniel Roseman