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? Mess开发者_如何学Cages 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
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.
精彩评论