Categories
Python Answers

How to redirect a post and pass on the post data with Python Django?

Spread the love

To redirect a post and pass on the post data with Python Django, we can redirect with HttpResponseRedirect.

For instance, we write

def some_view(request):
    #do some stuff
    request.session['_old_post'] = request.POST
    return HttpResponseRedirect('next_view')

def next_view(request):
    old_post = request.session.get('_old_post')
    #do some stuff using old_post

to create 2 views some_view and next_view.

In some_view, we return the HttpResponseRedirect response to redirect to next_view.

And in next_view we get the _old_post value from request.session that we saved in some_view.

And then we do stuff with the value.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *