How to clear or remove message, after displaying?

Hello everyone,

I’m using Django now for 4 years, I want to know how to clear or remove message after displaying?

I assume you mean the messages displayed by Django’s messages framework?

You’d have to use some JavaScript if you want to either make the message disappear after a certain amount of time, or else have a “close” link/button for the user to make it disappear.

One example of the latter is Bootstrap’s dismissible alerts: Alerts · Bootstrap v5.3

In addition to the above, you can also cause the message to go away by refreshing the page - either automatically (again with JavaScript) after some period of time or manually, with a button created to cause the page to reload.

Although that would be annoying for anyone part-way through reading the page, filling in a form, etc!

That is very true! Its utility is extremely limited. (e.g. A “dashboard” display page that auto-updates periodically)