Displaying a message after a POST/Redirect/GET

Sun 07 October 2007 | tags: django

I use the POST/Redirect/GET (RPG) pattern to avoid multiple submission problems. Sometimes however i want the GET part to display a message related to the POST part. Eg, “Your change has been done. Thank you” without creating special view just for this.
I found the solution to this problem in the www.djangosnippets.org site. It’s snippet no 319 titled “Flash Message Template Tag”.
What it does is use sessions and a special template tag to display a message in the template and immediately delete it from the session. After you set it up, all you have to do is something like this:

request.session['flash_msg'] = 'Your FOO has been BARed'
request.session['flash_params'] = {'type': 'success'}

Thanks Robert Conner!

Comments !