Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add request.GET variable using django.shortcuts.redirect

Is possible to add GET variables in a redirect ? (Without having to modifiy my urls.py)

If I do redirect('url-name', x)

I get HttpResponseRedirect('/my_long_url/%s/', x)

I don't have complains using HttpResponseRedirect('/my_long_url/%s/?q=something', x) instead, but just wondering...

like image 281
juanefren Avatar asked Sep 22 '10 02:09

juanefren


People also ask

How do I redirect in Django?

In Django, redirection is accomplished using the 'redirect' method. The 'redirect' method takes as argument: The URL you want to be redirected to as string A view's name. In the above example, first we imported redirect from django.

Can we send data with redirect in Django?

You can now perform a redirect with Django, either by using the redirect response classes HttpResponseRedirect and HttpResponsePermanentRedirect , or with the convenience function django. shortcuts. redirect() .

What is the difference between HttpResponseRedirect and redirect?

There is a difference between the two: In the case of HttpResponseRedirect the first argument can only be a url . redirect which will ultimately return a HttpResponseRedirect can accept a model , view , or url as it's "to" argument. So it is a little more flexible in what it can "redirect" to.

What is the difference between render and redirect in Django?

The render function Combines a given template with a given context dictionary and returns an HttpResponse object with that rendered text. You request a page and the render function returns it. The redirect function sends another request to the given url.


1 Answers

Since redirect just returns an HttpResponseRedirect object, you could just alter that:

response = redirect('url-name', x) response['Location'] += '?your=querystring' return response 
like image 85
SmileyChris Avatar answered Sep 25 '22 19:09

SmileyChris