您好,我正在尝试在 windows iis 7.5 环境中运行一些 python/django。启动服务器 (localhost:8888) 后,我收到以下错误。只有访问 localhost:8888 后才会产生此错误。
File "C:\Python27\lib\site-packages\django-1.5-py2.7.egg\django\core\handlers\
base.py", line 224, in handle_uncaught_exception
return callback(request, **param_dict)
File "C:\Python27\lib\site-packages\django-1.5-py2.7.egg\django\utils\decorato
rs.py", line 91, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "C:\Python27\lib\site-packages\ecm-2.1.2-py2.7.egg\ecm\views\custom_handl
ers.py", line 22, in server_error
http.HttpResponseServerError(t.render(RequestContext(request)))
File "C:\Python27\lib\site-packages\django-1.5-py2.7.egg\django\template\conte
xt.py", line 179, in __init__
self.update(processor(request))
File "C:\Python27\lib\site-packages\ecm-2.1.2-py2.7.egg\ecm\views\context_proc
essors.py", line 55, in menu
if request.user.is_superuser or UrlPermission.user_has_access(request.user,
menu['url']):
AttributeError: 'WSGIRequest' object has no attribute 'user'
<WSGIServer fileno=552 address=127.0.0.1:8888>: Failed to handle request:
request = GET /favicon.ico HTTP/1.1 from ('127.0.0.1', 50325)
application = <django.core.handlers.wsgi.WSGIHandler object at 0x022CDCB0>
我环顾四周并尝试了许多建议的解决方案 - 我在 django 中的中间件看起来像这样。
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
这是引用 request.user 行的代码。
def menu(request):
"""
Adds the variable {{ user_menu }} to all the templates.
The menu is composed with items from each ECM app/plugin (see the menu.py files)
The items are dynamically displayed according to user accesses.
"""
user_menus = []
for menu in ECM_MENUS:
if request.user.is_superuser or UrlPermission.user_has_access(request.user, menu['url']):
user_menus.append(menu)
data = {
'menus': user_menus,
'path': str(request.get_full_path())
}
return {'user_menu': render_to_string('ecm/menu.html', data), 'request_path': data['path']}
有什么想法吗?