Django message does not expire

My code in view:

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

I do not want to show this code to the user a second time if it is updated again. How can I do it? Messages do not seem to have any expiration conditions. There is documentation here:

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

+4
source share
1 answer

Messages are deleted as soon as you repeat messages (which should be accessible from RequestContext ).

So, the first step is to make sure you show the messages! If you want you to display messages for a specific page, you might want to explore stamping things into a session, but it gets a little messy to my liking. I can't think of any good reason to delay a message for the next pageload.

If you show them and your messages are hung longer than you expect, you may be re-adding them after they are displayed. Try putting timestamps in your messages and you will see when they were written.

+5
source

Source: https://habr.com/ru/post/1312323/


All Articles