CoderInNetwork CoderInNetwork - 3 months ago 16
Python Question

Pass value to another view django

I searched a lot but I didn't find a working solution and I even don't know the mechanism that makes redirect between two view possible.
I use

return HttpResponseRedirect(reverse('message-inbox', args=(),kwargs={}));


It works correctly.But I want to pass some values to message-inbox's View and retrieve them in that View.I thought about passing them to request object but I don't know if this is possible and also I don't know how I can do somethings like that.
I would be appreciate for any bit of help.

Answer

This is what the session is for.

In your source view:

request.session['my_key'] = my_value

And in your inbox view:

my_value = request.session['my_key']

Of course, if they're just small integers or strings, you could pass them in the URL parameters like any other view.

Comments