django apache2 ubuntu wsgi 错误无法导入 foobar.settings

标签 django apache ubuntu wsgi django-wsgi

你好,我找到了很多关于这个错误的东西,但对我来说仍然没有任何作用。
很抱歉再次询问。 :-)

错误(505)日志:

    [Wed Aug 28 19:02:59 2013] [error] [client 123] mod_wsgi (pid=19305): Exception occurred processing WSGI script '/usr/local/www/foo-app/foobar/wsgi.py'.
[Wed Aug 28 19:02:59 2013] [error] [client 123] Traceback (most recent call last):
[Wed Aug 28 19:02:59 2013] [error] [client 123]   File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 236, in __call__
[Wed Aug 28 19:02:59 2013] [error] [client 123]     self.load_middleware()
[Wed Aug 28 19:02:59 2013] [error] [client 123]   File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 45, in load_middleware
[Wed Aug 28 19:02:59 2013] [error] [client 123]     for middleware_path in settings.MIDDLEWARE_CLASSES:
[Wed Aug 28 19:02:59 2013] [error] [client 123]   File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 53, in __getattr__
[Wed Aug 28 19:02:59 2013] [error] [client 123]     self._setup(name)
[Wed Aug 28 19:02:59 2013] [error] [client 123]   File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 48, in _setup
[Wed Aug 28 19:02:59 2013] [error] [client 123]     self._wrapped = Settings(settings_module)
[Wed Aug 28 19:02:59 2013] [error] [client 123]   File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 134, in __init__
[Wed Aug 28 19:02:59 2013] [error] [client 123]     raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
[Wed Aug 28 19:02:59 2013] [error] [client 123] ImportError: Could not import settings 'foobar.settings' (Is it on sys.path?): No module named foobar.settings

我的 wsgi.py 文件:
import os
import sys

# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
# if running multiple sites in the same mod_wsgi process. To fix this, use
# mod_wsgi daemon mode with each site in its own daemon process, or use
# os.environ["DJANGO_SETTINGS_MODULE"] = "foobar.settings"
sys.path.append('/usr/local/www/foobar-app/foobar')
sys.path.append('/var/www')
sys.path.append('/var/www/foobar')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "foobar.settings")

# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

本地所有工作。

感谢您的每一个帮助!

伟大的

最佳答案

您应该添加:

/usr/local/www/foobar-app

到 sys.path。看:
  • https://docs.djangoproject.com/en/1.5/howto/deployment/wsgi/modwsgi/
  • 关于django apache2 ubuntu wsgi 错误无法导入 foobar.settings,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18494224/

    相关文章:

    python - 狮身人面像添加背景图像

    django - 测试时在 Django 中使用 session 对象?

    python - DRF3 在 m2m 关系上创建嵌套序列化器

    javascript - jQuery + Django : get data from HTML table

    php - 使用 htaccess 从 URL 中删除 .php

    mysql - 如何在phpmyadmin MySql中导入记事本.txt文件

    python - 如何在 ubuntu 上安装 python 模块 sys、os 和 getopt?

    ruby-on-rails - s3sh 命令行 ubuntu 仍然存在(EC2,s3 amazon)

    java - 这是 Apache + Tomcat 之间的虚假 SSL 连接吗?

    c++ - Ubuntu 16.04,Nvidia toolkit 8.0 RC,暗网编译错误: expected a ";"