Question

#view1

...
    p = Model_Name.objects.get(pk=1)
    var_to_send = p.field_in_model
    return HttpResponseRedirect(reverse('namespace:name'))

#view2

def View2(request, var)
    #do something to var

I want to be able to send var_to_send to View2.

Was it helpful?

Solution 2

How about HttpResponseRedirect(reverse('namespace:name', args=(var_to_send,)))

OTHER TIPS

HttpResponseRedirect performs a HTTP 301 redirect, changing the url in the browser's bar.

You can pass the var as args and reverse will build the url to match your patterns. See the following answer related to this https://stackoverflow.com/a/13202435/948416

But also you can call the View2 function and return that result instead of the redirect:

...
p = Model_Name.objects.get(pk=1)
var_to_send = p.field_in_model
return View2(request, var_to_send)

The second approach is better for me because it doesn't require any additional HTTP request.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top