我将djang1.3.1更新为djang1.4,错误:MOD_PYTHON ERROR

时间:2012-04-08 12:28:09

标签: python django mod-python

我将djang1.3.1更新为djang1.4。
在我当地的环境中,那没关系 但当我把我的代码发送到服务器时,发生了错误! 在我的服务器中,我可以使用'python manage.py shell'
并且可以'导入设置',这没关系,
但仍然有这个错误,谁可以帮助我!

  

最后,我卸载了apache,并安装了nginx + uwsgi,修复了   这个问题.......

Traceback (most recent call last):

File "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line 1537, in HandlerDispatch
default=default_handler, arg=req, silent=hlist.silent)

File "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line 1229, in _process_target
result = _execute_target(config, req, object, arg)

File "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line 1128, in _execute_target
result = object(arg)

File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/modpython.py", line 180, in handler
return ModPythonHandler()(req)

File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/modpython.py", line 142, in __call__
self.load_middleware()

File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py", line 39, in load_middleware
for middleware_path in settings.MIDDLEWARE_CLASSES:

File "/usr/local/lib/python2.6/dist-packages/django/utils/functional.py", line 184, in inner
self._setup()

File "/usr/local/lib/python2.6/dist-packages/django/conf/__init__.py", line 42, in _setup
self._wrapped = Settings(settings_module)

File "/usr/local/lib/python2.6/dist-packages/django/conf/__init__.py", line 95, in __init__
raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))

ImportError: Could not import settings 'guihuame.settings' (Is it on sys.path?): No module named guihuame.settings

我的python版本

Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> django.VERSION
(1, 4, 0, 'final', 0)

使用manage.py

python manage.py shell
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import settings
Traceback (most recent call last):
  File "<console>", line 1, in <module>
ImportError: No module named settings
>>> import guihuame.settings
>>> 

THX!

我的文档树是
guihuame
- manage.py
- guihuame(包含 init .py wsgi.py settings.py urls.py)
- 其他应用

我的wsgi.py,wsgi.py和settings.py位于同一个文件夹中

import os
import sys
sys.path.insert(0, '/var/web/trunk/guihuame/')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "guihuame.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

1 个答案:

答案 0 :(得分:2)

您需要在wsgi.py添加一行,以便将guihuame模块的位置添加到PYTHONPATH:

import sys
sys.path.insert(0, 'Wherever guihuame is')

更新: 您可以实际提供guihame的位置。但是,不要对路径进行字符串操作。 Python将选择正确的分隔符。如果存在问题,请使用normpath

另请注意,os.path.split(os.path.dirname(__file__))[0]正在选择您的文件系统根目录,或者更可能选择低于它的一个级别。这可能不是你想要的。