0

我创建了一个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()

有什么帮助吗?

4

1 回答 1

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(相同的用法)。

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

于 2013-12-12T03:08:00.530 回答