こんにちは、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']}
何かご意見は?