2

I updated djang1.3.1 to djang1.4.
In my local env ,that's fine.
but when i ci my code to server ,error happened!
in my server , i can use 'python manage.py shell'
and can 'import settings', that's all right,
but still have this error, who can help me!

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

my python version

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)

use 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!

my document tree is
guihuame
-- manage.py
-- guihuame (contains init.py wsgi.py settings.py urls.py)
-- other apps

my wsgi.py , wsgi.py and settings.py are in the same folder

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()
yzliu
  • 21
  • 3

1 Answers1

2

You need to add a line to wsgi.py to add the location of your guihuame module to the PYTHONPATH:

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

Update: It's up to you to actually provide the location of guihame. However, don't do string manipulations on your paths. Python will choose the correct separator. If there is an issue with that, use normpath.

Note also that os.path.split(os.path.dirname(__file__))[0] is selecting either your filesystem root, or more likely, just one level below it. This is probably not what you want.

Marcin
  • 48,559
  • 18
  • 128
  • 201
  • import sys root_path = os.path.split(os.path.dirname(__file__))[0] sys.path.insert(0, os.path.join(root_path, 'guihuame').replace('\\','/')) it doesn't work~ – yzliu Apr 08 '12 at 12:51
  • @yzliu What you have pasted is not valid python, and it is not the code I have suggested. Update your answer with the current state of your wsgi.py and I *may* be able to help you, if you also describe the nature of the error you are experiencing. – Marcin Apr 08 '12 at 12:54