Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django message doesn't expire

My code in the view:

   from django.contrib import messages
   messages.add_message(request, messages.INFO, 'Hello world.')

I don't want to show this code to the user the second time if he/she refreshes again. How do I go about doing that? Messages don't seem to have any sort of expiry setting. There is documentation here:

http://docs.djangoproject.com/en/1.2/ref/contrib/messages/#expiration-of-messages

like image 536
ninja123 Avatar asked Jun 09 '10 13:06

ninja123


1 Answers

Messages are cleared as soon as you iterate messages (which should be available from RequestContext).

So step one is making sure you're displaying messages! If you want to hold-off on displaying messages for a certain page, you'll perhaps want to investigate punching things into session but it's getting a bit messy for my liking. I can't think of any good reasons to delay the message for the next pageload.

If you are displaying them and your messages are hanging on longer than you expect, perhaps you're re-adding them after they're being displayed. Try putting timestamps into your messages and you'll see if when they were written.

like image 61
Oli Avatar answered Nov 16 '22 14:11

Oli