简体   繁体   中英

How can I display a global alert in Django admin panel?

I don't want it to show up after performing an action, I want it to show up on all pages of the Django admin panel.

Is this possible?

Is it a static message? I'd just override the necessary admin templates and not use django.contrib.messages as you may be tempted to - it may be confusing to the user.

A loooong time ago I used django-persistent-messages for this.

Users will get a message across the top of the page which will only go away after they dismiss it by clicking on an X icon. You can use different degrees of alertness (info, warning, error, critical) so it's pretty useful.

The one caveat is that, in order to make the messages persistent, they are linked to a user account. If your website uses anonymous users you will have to think of something else (perhaps a javascript approach with cookies or one of the more modern browser storage methods)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM