2012-04-08 99 views
2

我更新了djang1.3.1到djang1.4。
在我的本地環境中,沒關係。
但是當我ci我的代碼到服務器,發生錯誤!
在我的服務器上,我可以使用'python manage.py shell'
並且可以'導入設置',沒關係,
但是仍然有這個錯誤,誰能幫幫我!
我更新djang1.3.1到djang1.4,錯誤:MOD_PYTHON錯誤

finally, i uninstalled apache , and installed nginx + uwsgi ,fixed this problem.......

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(包含初始化的.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() 
+0

您需要正確設置您的PYTHONPATH。顯示你的WSGI文件。 – Marcin 2012-04-08 12:32:30

+0

這是我的wsgi.py,看問題底部 – yzliu 2012-04-08 12:38:25

+0

除非你在'/ var/web/trunk/guihuame /'目錄下還有一個guihuame目錄,否則你可能想把它改成''/ var/web/' – Marcin 2012-04-08 14:12:58

回答

2

ÿ OU需要添加一行wsgi.pyguihuame模塊的位置添加到PYTHONPATH:

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

更新: 這取決於你實際提供的guihame位置。但是,不要對你的路徑進行字符串操作。 Python會選擇正確的分隔符。如果有問題,請使用normpath

還要注意,os.path.split(os.path.dirname(__file__))[0]正在選擇您的文件系統根目錄,或者更可能的是,選擇它下面的一個級別。這可能不是你想要的。

+0

import sys root_path = os.path.split(os.path.dirname(__ file __))[0] sys.path.insert(0,os.path.join(root_path,'guihuame')。替換('\\','/'))它不起作用〜 – yzliu 2012-04-08 12:51:00

+0

@yzliu你粘貼的是不是有效的Python,它不是我建議的代碼。如果您還描述了您遇到的錯誤的性質,請使用wsgi.py的當前狀態更新您的答案,我*可能*能夠幫助您。 – Marcin 2012-04-08 12:54:07

+0

對不起,我已經更新了這個問題。見底部 – yzliu 2012-04-08 13:02:27