偶尔出现500错误

发布于 2024-10-20 03:04:30 字数 1455 浏览 6 评论 0原文

我们使用 Apache+mod_wsgi 来托管 Django 应用程序。

Apache:

WSGIScriptAlias / /home/rls/django_wsgi.py

django_wsgi.py:

import os, sys
sys.path.append('data/misc/django')
os.environ['DJANGO_SETTINGS_MODULE'] = 'rls.settings'

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

一切正常,但偶尔我们会在日志中收到 500 内部服务器错误:

mod_wsgi (pid=4825): Exception occurred processing WSGI script '/home/rls/django_wsgi.py'.
Traceback (most recent call last):
File "/usr/lib/python2.5/site-packages/django/core/handlers/wsgi.py", line 230, in __call__
self.load_middleware()
File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py", line 33, in load_middleware
for middleware_path in settings.MIDDLEWARE_CLASSES:
File "/usr/lib/python2.5/site-packages/django/utils/functional.py", line 276, in __getattr__
self._setup()
File "/usr/lib/python2.5/site-packages/django/conf/__init__.py", line 40, in _setup
self._wrapped = Settings(settings_module)
File "/usr/lib/python2.5/site-packages/django/conf/__init__.py", line 75, in __init__
raise ImportError("Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'rls.settings' (Is it on sys.path? Does it have syntax errors?): No module named rls.settings

当然,设置中没有语法错误.py 因为它每隔一段时间就加载得很好。我缺少什么?非常感谢您的帮助。

We use Apache+mod_wsgi to host our Django application.

Apache:

WSGIScriptAlias / /home/rls/django_wsgi.py

django_wsgi.py:

import os, sys
sys.path.append('data/misc/django')
os.environ['DJANGO_SETTINGS_MODULE'] = 'rls.settings'

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

Everything works fine, but occasionally we get 500 Internal Server Error with this in the logs:

mod_wsgi (pid=4825): Exception occurred processing WSGI script '/home/rls/django_wsgi.py'.
Traceback (most recent call last):
File "/usr/lib/python2.5/site-packages/django/core/handlers/wsgi.py", line 230, in __call__
self.load_middleware()
File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py", line 33, in load_middleware
for middleware_path in settings.MIDDLEWARE_CLASSES:
File "/usr/lib/python2.5/site-packages/django/utils/functional.py", line 276, in __getattr__
self._setup()
File "/usr/lib/python2.5/site-packages/django/conf/__init__.py", line 40, in _setup
self._wrapped = Settings(settings_module)
File "/usr/lib/python2.5/site-packages/django/conf/__init__.py", line 75, in __init__
raise ImportError("Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'rls.settings' (Is it on sys.path? Does it have syntax errors?): No module named rls.settings

Of course there are no syntax errors in settings.py since it loads fine every other time. What I'm missing? Thanks very much for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

成熟稳重的好男人 2024-10-27 03:04:30

尝试将绝对路径设置为包含文件settings.py 的目录。
在您的情况下应该是这样的:

sys.path.append('/%s/data/misc/django'%ROOT_2_DATA)

您还必须检查 apache 组是否具有读/写该文件夹的权限。

Try to set the absolute path to the directory that contains the file settings.py.
In your case should be something like:

sys.path.append('/%s/data/misc/django'%ROOT_2_DATA)

You must also check that apache group has permissions to read/write the folder.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文