tags:

views:

57

answers:

2

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.

+4  A: 

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 the uses_passes_test function - the bit to add the message would have to go before return HttpResponseRedirect.

Daniel Roseman
A: 

Try using this: http://code.google.com/p/django-session-messages/

or use Django 1.2 (currently in Beta) and the messages framework: http://docs.djangoproject.com/en/dev/ref/contrib/messages/#ref-contrib-messages

Frozenskys