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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With