【问题标题】:Django: Internal Server ErrorDjango:内部服务器错误
【发布时间】:2023-03-25 22:43:01
【问题描述】:

这是我第一次在 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$

我真的不明白问题出在哪里以及如何处理。

【问题讨论】:

    标签: python django nginx digital-ocean


    【解决方案1】:

    根据documentation

    Django 1.7 中的新功能。

    允许用户的会话在其密码更改时失效。有关详细信息,请参阅Session invalidation on password change。此中间件必须出现在MIDDLEWARE_CLASSES 中的django.contrib.auth.middleware.AuthenticationMiddleware 之后。

    因此,我的猜测是您不在 Django 1.7+ 上,但您已在 MIDDLEWARE_CLASSES 中定义了 django.contrib.auth.middleware.SessionAuthenticationMiddleware

    请参阅Sessions Documentation

    要启用会话功能,请执行以下操作:

    编辑 MIDDLEWARE_CLASSES 设置并确保它包含 'django.contrib.sessions.middleware.SessionMiddleware'django-admin.py startproject 创建的默认 settings.py 已激活 SessionMiddleware

    如果您不想使用会话,不妨从 MIDDLEWARE_CLASSES'django.contrib.sessions' 中删除 SessionMiddleware 行来自您的 INSTALLED_APPS。它会为您节省一点开销。

    【讨论】:

      猜你喜欢
      • 2011-03-18
      • 2015-06-25
      • 2018-11-23
      • 2017-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-05
      • 2015-02-12
      相关资源
      最近更新 更多