问题描述:

There is a project setup with Django 1.6 and Django allauth. when user logged in django saves a login message to users session and its stack in there. While user reached to any page included messages framework, login message shows up with other message.

Because of this reason, I want to remove login message from message queue after user logged in.

I tried remove login message in django's and allauth's user_logged_in signal, but I discovered the message is not created there.

The example of the message removal code is below:

# from allauth.account.signals import user_logged_in

# First I tried allauth signal above.

from django.contrib.auth.signals import user_logged_in

@receiver(user_logged_in)

def user_logged_in_(request, **kwargs):

storage = messages.get_messages(request)

storage.used = True

Edit: The workaround below is working. But I feel it is not right way to do.

After this, I decided to make a workaround. After user logged in, user redirected to index view. I removed signal and append storage.used = True method in index view. Also It is not worked too.

def clear_messages(request):

storage = messages.get_messages(request)

storage.used = True

def index(request):

clear_messages(request)

return render_to_response('website/index.html', {}, context_instance=RequestContext(request, {}))

网友答案:

From django-allauth's documentation:

All messages (as in django.contrib.messages) are configurable by overriding their respective template. If you want to disable a message simply override the message template with a blank one.

相关阅读:
Top