[Fixed]-HttpResponseRedirect with reverse not passing parameters

0👍

It it because you are asking for fail from GET but you are not passing anything in GET.

you need:

return HttpResponseRedirect('%s?fail=%s' % (reverse('home'), True))

then you can catch it like:

request.GET.get("fail", False)

dont misuse Booleans! 😉

1👍

The args and kwargs passed to the HttpResponseRedirect constructor

def __init__(self, redirect_to, *args, **kwargs):
    ...

are not being used to construct a QueryDict (get or post). You are initialising a response here, not a request. As doniyor has already stated you basically have to append the querystring manually to the path returned by reverse():

return HttpResponseRedirect('{to}?{query}'.format(
    to=reverse('home'),
    query=urllib.urlencode({"fail":"true"})
))

This has nothing to do with django, but general http redirection. You can only redirect a request to a location (to which you can add a query string), but you cannot tamper with the request itself, like adding POST-data or setting headers.

0👍

You need give a second parameter at reverse function… as de arguments… this works well for me!!!

    return reverse('home', args='true')

Leave a comment