【问题标题】:When logout from django admin: "AnonymousUser" object has no attribute "get_and_delete_messages"从 django 管理员注销时:“AnonymousUser”对象没有属性“get_and_delete_messages”
【发布时间】:2013-12-11 14:58:38
【问题描述】:

我通过

创建了一个 askbot 项目
askbot-setup

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

我从 shell 创建了一个超级用户:

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

然后我运行开发服务器并通过浏览器访问本地主机

python manage.py runserver

一切似乎都很好。但是当我从管理页面注销时,出现异常:

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

追溯:

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()

有什么帮助吗?

【问题讨论】:

    标签: django-admin askbot


    【解决方案1】:

    我找到了解决办法。

    我也在http://askbot.org/en/question/11782/admin-logout-throw-exception/ 上发布了这个,使用hailong 作为用户名。

    我通过修改/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)
    

    因为我发现函数 get_and_delete_messages 在该文件中仅定义为“独立”函数,而不是某个类的方法。但它被用作request.user.get_and_delete_messages()。我认为这是一个错字。如果我是对的,/usr/local/lib/python2.7/dist-packages/askbot/user_messages/__init__.py 中还有另一个错字(用法相同)。

    如果我错了,请纠正我。但我的解决方案很可能有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-13
      • 2019-10-21
      • 2015-06-11
      • 1970-01-01
      • 1970-01-01
      • 2012-03-06
      • 1970-01-01
      相关资源
      最近更新 更多