add request.GET variable using django.shortcuts.redirect

juanefren picture juanefren · Sep 22, 2010 · Viewed 27k times · Source

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...

Answer

SmileyChris picture SmileyChris · Sep 22, 2010

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

response = redirect('url-name', x)
response['Location'] += '?your=querystring'
return response