2

djang1.3.1 を djang1.4 にアップデートしました。
私のローカル環境では、それで問題ありません。
しかし、コードをサーバーにciすると、エラーが発生しました!
私のサーバーでは、「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
>>> 

どうも!

私のドキュメント ツリーは
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()
4

1 に答える 1

2

wsgi.pyモジュールの場所をguihuamePYTHONPATHに追加するには、次の行を追加する必要があります。

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

更新: の場所を実際に提供するのはあなた次第ですguihame。ただし、パスで文字列操作を行わないでください。Python は正しいセパレータを選択します。問題がある場合は、 を使用してnormpathください。

os.path.split(os.path.dirname(__file__))[0]また、ファイルシステムのルート、またはその 1 レベル下のいずれかを選択していることにも注意してください。これはおそらくあなたが望むものではありません。

于 2012-04-08T12:41:51.723 に答える