我通过
创建了一个 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')
然后我运行dev服务器并通过浏览器访问localhost
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()
任何帮助?
答案 0 :(得分:0)
我找到了解决方案。
我还在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
(相同用法)。
如果我错了,请纠正我。但这可能是我的解决方案有效。