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...
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.
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() .
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.
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.
Since redirect just returns an HttpResponseRedirect
object, you could just alter that:
response = redirect('url-name', x) response['Location'] += '?your=querystring' return response
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