部署django:导入设置时出错,是否在sys.path上?

时间:2013-08-02 16:56:36

标签: django apache2 django-wsgi

我正在尝试首次部署django网站。 我正在使用Django 1.5.1 我遵循教程,但是我在apache中遇到错误:

[Fri Aug 02 19:48:03 2013] [error] [client 109.8.106.183] mod_wsgi (pid=10767): Exception occurred processing WSGI script '/var/www/html/portail_public/geocameroun/geocameroun/wsgi.py'.
[Fri Aug 02 19:48:03 2013] [error] [client 109.8.106.183] Traceback (most recent call last):
[Fri Aug 02 19:48:03 2013] [error] [client 109.8.106.183]   File "/usr/lib/python2.6/site-packages/django/core/handlers/wsgi.py", line 236, in __call__
[Fri Aug 02 19:48:03 2013] [error] [client 109.8.106.183]     self.load_middleware()
[Fri Aug 02 19:48:03 2013] [error] [client 109.8.106.183]   File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py", line 45, in load_middleware
[Fri Aug 02 19:48:03 2013] [error] [client 109.8.106.183]     for middleware_path in settings.MIDDLEWARE_CLASSES:
[Fri Aug 02 19:48:03 2013] [error] [client 109.8.106.183]   File "/usr/lib/python2.6/site-packages/django/conf/__init__.py", line 53, in __getattr__
[Fri Aug 02 19:48:03 2013] [error] [client 109.8.106.183]     self._setup(name)
[Fri Aug 02 19:48:03 2013] [error] [client 109.8.106.183]   File "/usr/lib/python2.6/site-packages/django/conf/__init__.py", line 48, in _setup
[Fri Aug 02 19:48:03 2013] [error] [client 109.8.106.183]     self._wrapped = Settings(settings_module)
[Fri Aug 02 19:48:03 2013] [error] [client 109.8.106.183]   File "/usr/lib/python2.6/site-packages/django/conf/__init__.py", line 134, in __init__
[Fri Aug 02 19:48:03 2013] [error] [client 109.8.106.183]     raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
[Fri Aug 02 19:48:03 2013] [error] [client 109.8.106.183] ImportError: Could not import settings 'geocameroun.settings' (Is it on sys.path?): No module named settings

这个错误似乎非常频繁,我有很多回复但是其中任何一个都解决了我的问题,或者我可能听不懂。

我检查geocameroun.settings是否在sys.path上,所以我添加了geocameroun / wsgi.py:

print "path"
print sys.path

path = '/var/www/html/portail_public/geocameroun/'
if path not in sys.path:
    sys.path.insert(0, '/var/www/html/portail_public/geocameroun/')
path = '/var/www/html/portail_public/geocameroun/geocameroun'
if path not in sys.path:
    sys.path.insert(0, '/var/www/html/portail_public/geocameroun/geocameroun')
print sys.path

在apache中我得到了这个:

[Fri Aug 02 19:48:03 2013] [error] ['/var/www/html/portail_public/geocameroun/geocameroun', '/usr/lib/python2.6/site-packages/MapProxy-1.5.0-py2.6.egg', '/usr/lib/python2.6/site-packages/PyYAML-3.10-py2.6-linux-x86_64.egg', '/usr/lib64/python26.zip', '/usr/lib64/python2.6', '/usr/lib64/python2.6/plat-linux2', '/usr/lib64/python2.6/lib-tk', '/usr/lib64/python2.6/lib-old', '/usr/lib64/python2.6/lib-dynload', '/usr/lib64/python2.6/site-packages', '/usr/lib64/python2.6/site-packages/PIL', '/usr/lib/python2.6/site-packages', '/usr/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg-info', '/var/www/html/portail_public/geocameroun']

所以没关系,不是吗? settings.py位于/ var / www / html / portail_public / geocameroun / geocameroun /

在我的wgsi.py中,我尝试了这两行:

#os.environ.setdefault("DJANGO_SETTINGS_MODULE", "geocameroun.settings")
os.environ["DJANGO_SETTINGS_MODULE"] = "geocameroun.settings"

关于开发网络服务器,它在此文件夹中无效/ var / www / html / portail_public

/geocameroun :Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/lib/python2.6/site-packages/django/core/management/__init__.py", line 453, in execute_from_command_line
    utility.execute()
  File "/usr/lib/python2.6/site-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib/python2.6/site-packages/django/core/management/__init__.py", line 263, in fetch_command
    app_name = get_commands()[subcommand]
  File "/usr/lib/python2.6/site-packages/django/core/management/__init__.py", line 109, in get_commands
    apps = settings.INSTALLED_APPS
  File "/usr/lib/python2.6/site-packages/django/conf/__init__.py", line 53, in __getattr__
    self._setup(name)
  File "/usr/lib/python2.6/site-packages/django/conf/__init__.py", line 48, in _setup
    self._wrapped = Settings(settings_module)
  File "/usr/lib/python2.6/site-packages/django/conf/__init__.py", line 134, in __init__
    raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'geocameroun.settings' (Is it on sys.path?): No module named settings

但它适用于我在/ home / etienne / geocameroun中的真实开发版本。 此致

0 个答案:

没有答案