How to pass information using an HTTP redirect (in Django)

后端 未结 11 848
北恋
北恋 2021-02-01 19:22

I have a view that accepts a form submission and updates a model.

After updating the model, I want to redirect to another page, and I want a message such as \"Field X su

11条回答
  •  别那么骄傲
    2021-02-01 20:21

    There is a lot of solutions

    1 Use Django-trunk version - it support sending messages to Anonymous Users

    2 Sessions

    def view1(request):
        request.session['message'] = 'Hello view2!'
        return HttpResponseRedirect('/view2/')
    
    
    def view2(request):
        return HttpResponse(request.session['message'])
    

    3 redirect with param

    return HttpResponseRedirect('/view2/?message=Hello+view2')
    

    4 Cookies

提交回复
热议问题