How do I use messages with third-party views?
I've implemented a notification bar using django.contrib.messages
. Now, I w开发者_StackOverflowant to make extended use of it, e.g. to display a "Welcome back" or "Logout successful" messages. However, I prefer to use builtin views for basic actions, so I use django.contrib.auth.views.logout_then_login
for logging out and django.contrib.auth.views.login
for logging in. Therefore, there isn't a single place where I could insert my messages.success(...)
, since those views are not mine.
Is there an elegant way to add those messages nevertheless without copying or overwriting views?
Signals are your friends. See in particular the login and logout signals.
精彩评论