开发者

How do I use messages with third-party views?

开发者 https://www.devze.com 2023-03-25 11:29 出处:网络
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. Ho

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消