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

后端 未结 11 883
北恋
北恋 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:22

    Can you just pass the message as a query param oon the URL to which you're redirecting? It's not terribly RESTy, but it ought to work:

    return HttpResponseRedirect('/polls/%s/results/?message=Updated" % p.id)
    

    and have that view check for a message param, scrub it for nasties, and display it at the top.

提交回复
热议问题