I’m using the Django Message Framework to show messages to users as well as the @login_required decorator on one of my views. So if a user tries to access a certain view without being logged in, they get kicked to the login page. How would I go about adding an error message to the login page saying “In order to do … you must be logged in”. I can’t add it in the view like you normally would because the non-logged in user would never get to there.
I’m using the Django Message Framework to show messages to users as well as
Share
There’s not any obvious way. The only thing that springs to mind is to write your own version of the decorator that puts a message into the session before redirecting, then get the login template to display the message from the session.
You’d need to use the code in
django.contrib.auth.decorators, in particular theuser_passes_testfunction – the bit to add the message would have to go beforereturn HttpResponseRedirect.