When logout from django admin: "AnonymousUser" object has no attribute "get_and_delete_messages"

StackOverflow https://stackoverflow.com/questions/20522412

  •  31-08-2022
  •  | 
  •  

Question

I created a askbot project by

askbot-setup

and

python manage.py syncdb # answered 'no' when asked to create superuser account
python manage.py migrate

I create a superuse from the shell:

from django.contrib.auth.models import User
User.objects.create_superuser('admin', admin@example.com', 'pass')

then I run the dev server and visit localhost from by browser

python manage.py runserver

Everything seems fine. But when I logout from the admin page, exception occurs:

AttributeError at /admin/logout/
'AnonymousUser' object has no attribute 'get_and_delete_messages'
Request Method: GET
Request URL:    http://localhost:8000/admin/logout/
Django Version: 1.5
Exception Type: AttributeError
Exception Value:    
'AnonymousUser' object has no attribute 'get_and_delete_messages'
Exception Location: /usr/local/lib/python2.7/dist-packages/askbot/user_messages/context_processors.py in user_messages, line 21
Python Executable:  /usr/bin/python
Python Version: 2.7.4

Tracebacks:

Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  140.                     response = response.render()
File "/usr/local/lib/python2.7/dist-packages/django/template/response.py" in render
  105.             self.content = self.rendered_content
File "/usr/local/lib/python2.7/dist-packages/django/template/response.py" in rendered_content
  81.         context = self.resolve_context(self.context_data)
File "/usr/local/lib/python2.7/dist-packages/django/template/response.py" in resolve_context
  159.         return RequestContext(self._request, context, current_app=self._current_app)
File "/usr/local/lib/python2.7/dist-packages/django/template/context.py" in __init__
  179.             self.update(processor(request))
File "/usr/local/lib/python2.7/dist-packages/askbot/user_messages/context_processors.py" in user_messages
  21.     messages = request.user.get_and_delete_messages()

Any help?

Was it helpful?

Solution

I found the solution.

I also posted this at http://askbot.org/en/question/11782/admin-logout-throw-exception/, using hailong as user name.

I solved that problem by modifying /usr/local/lib/python2.7/dist-packages/askbot/user_messages/context_processors.py

# messages = request.user.get_and_delete_messages() .... original, prox. line 22
messages = get_and_delete_messages(request)

Because I find function get_and_delete_messages only defined as a "standalone" function in that file, and never a method of some class. But it is used as request.user.get_and_delete_messages(). I assume it's a typo. If I am right, another typo is in /usr/local/lib/python2.7/dist-packages/askbot/user_messages/__init__.py (same usage).

Correct me if I am wrong. But it's likely my solution works.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top