Django:内部服务器错误
Django: Internal Server Error
这是我第一次在 DigitalOcean 上部署 Django 网站,这给我带来了很多问题。我正在使用一键安装,从 git 部署了我的网站并更改了 gunicorn 和 nginx 文件,但它仍然给我
Internal Server Error.
这是 Apache 日志:
2015-05-18 15:24:08 [20726] [ERROR] Error handling request Traceback
(most recent call last): File
"/usr/lib/python2.7/dist-packages/gunicorn/workers/async.py", line
45, in handle
self.handle_request(listener, req, client, addr) File "/usr/lib/python2.7/dist-packages/gunicorn/workers/ggevent.py", line
119, in handle_r$
super(GeventWorker, self).handle_request(*args) File "/usr/lib/python2.7/dist-packages/gunicorn/workers/async.py", line
93, in handle_requ$
respiter = self.wsgi(environ, resp.start_response) File "/usr/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line
187, in __call__
self.load_middleware() File "/usr/lib/python2.7/dist-packages/django/core/handlers/base.py", line
45, in load_mid$
mw_class = import_by_path(middleware_path) File "/usr/lib/python2.7/dist-packages/django/utils/module_loading.py",
line 31, in import$
error_prefix, module_path, class_name)) ImproperlyConfigured: Module "django.contrib.auth.middleware" does not define a
"SessionAuth$
实在搞不懂问题出在哪里,如何处理。
根据 documentation:
New in Django 1.7.
Allows a user’s sessions to be invalidated when their password changes. See Session invalidation on password change for details. This middleware must appear after django.contrib.auth.middleware.AuthenticationMiddleware
in MIDDLEWARE_CLASSES
.
因此,我的猜测是您没有使用 Django 1.7+,但您已经在 MIDDLEWARE_CLASSES
.
中定义了 django.contrib.auth.middleware.SessionAuthenticationMiddleware
<= Django 1.6
To enable session functionality, do the following:
Edit the MIDDLEWARE_CLASSES
setting and make sure it contains 'django.contrib.sessions.middleware.SessionMiddleware'
. The default settings.py created by django-admin.py startproject has SessionMiddleware activated.
If you don’t want to use sessions, you might as well remove the SessionMiddleware line from MIDDLEWARE_CLASSES
and 'django.contrib.sessions'
from your INSTALLED_APPS
. It’ll save you a small bit of overhead.
这是我第一次在 DigitalOcean 上部署 Django 网站,这给我带来了很多问题。我正在使用一键安装,从 git 部署了我的网站并更改了 gunicorn 和 nginx 文件,但它仍然给我
Internal Server Error.
这是 Apache 日志:
2015-05-18 15:24:08 [20726] [ERROR] Error handling request Traceback
(most recent call last): File
"/usr/lib/python2.7/dist-packages/gunicorn/workers/async.py", line
45, in handle
self.handle_request(listener, req, client, addr) File "/usr/lib/python2.7/dist-packages/gunicorn/workers/ggevent.py", line
119, in handle_r$
super(GeventWorker, self).handle_request(*args) File "/usr/lib/python2.7/dist-packages/gunicorn/workers/async.py", line
93, in handle_requ$
respiter = self.wsgi(environ, resp.start_response) File "/usr/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line
187, in __call__
self.load_middleware() File "/usr/lib/python2.7/dist-packages/django/core/handlers/base.py", line
45, in load_mid$
mw_class = import_by_path(middleware_path) File "/usr/lib/python2.7/dist-packages/django/utils/module_loading.py",
line 31, in import$
error_prefix, module_path, class_name)) ImproperlyConfigured: Module "django.contrib.auth.middleware" does not define a
"SessionAuth$
实在搞不懂问题出在哪里,如何处理。
根据 documentation:
New in Django 1.7.
Allows a user’s sessions to be invalidated when their password changes. See Session invalidation on password change for details. This middleware must appear after
django.contrib.auth.middleware.AuthenticationMiddleware
inMIDDLEWARE_CLASSES
.
因此,我的猜测是您没有使用 Django 1.7+,但您已经在 MIDDLEWARE_CLASSES
.
django.contrib.auth.middleware.SessionAuthenticationMiddleware
<= Django 1.6
To enable session functionality, do the following:
Edit the
MIDDLEWARE_CLASSES
setting and make sure it contains'django.contrib.sessions.middleware.SessionMiddleware'
. The default settings.py created by django-admin.py startproject has SessionMiddleware activated.If you don’t want to use sessions, you might as well remove the SessionMiddleware line from
MIDDLEWARE_CLASSES
and'django.contrib.sessions'
from yourINSTALLED_APPS
. It’ll save you a small bit of overhead.