Python – django Authentication using auth.views


User should be redirected to the Login page after registration and after logout. In both cases there must be a message displayed indicating relevant messages.

Using the django.contrib.auth.views.login how do I send these {{ info }} messages.

A possible option would be to copy the auth.views to new registration module and include all essential stuff. But that doesn't seem DRY enough.

What is the best approach.

Update: Question elaboration:

For normal cases when you want to indicate to some user the response of an action you can use


This creates a message that is displayed in one of the templates and automatically deletes.

However this message system only works for logged in users who continue to have same session id. In the case of registration, the user is not authenticated and in the case of logout since the session changes, this system cannot be used.

Add to that, the built in login and logout functions from django.contrib.auth.views return a 'HttpResponseRedirect' which make it impossible to add another variable to the template.

I tried setting things on the request object itself'Registered'

and check this in a different view

   info =
   info = ''


Even this didn't work.

Clearly I can define a registered.html and add this static message there, but I was being lazy to write another template and trying to implement it DRY.

I realized that the cases were different for "registered" message and "logged out" message. And the DRY approach I used, I shall write as an answer.

Best Solution

I think the best solution to this problem is to use a "flash"-type session-based messaging system. There are several floating around: django-flash seems really nice, I use django-session-messages which is very simple. Hopefully by the time we get to Django 1.2 this'll be baked-in.