2010-03-26 75 views
0

我想一個共享的主機部署我的Django項目的描述here設置模塊

我有我的項目上的/ home /用戶/網絡/種皮

我使用這個腳本


#!/usr/bin/python 
import sys, os 

sys.path.append("/home/user/bin/python") 

sys.path.append('/home/user/www/testa') 


os.chdir("/home/user/www/testa") 

os.environ['DJANGO_SETTINGS_MODULE'] = "settings.py" 

from django.core.servers.fastcgi import runfastcgi 
runfastcgi(method="threaded", daemonize="false") 

這裏是我得到的錯誤試圖從shell中運行它時:


WSGIServer: missing FastCGI param REQUEST_METHOD required by WSGI! 
WSGIServer: missing FastCGI param SERVER_NAME required by WSGI! 
WSGIServer: missing FastCGI param SERVER_PORT required by WSGI! 
WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI! 
Traceback (most recent call last): 
    File "build/bdist.linux-i686/egg/flup/server/fcgi_base.py", line 558, in run 
    File "build/bdist.linux-i686/egg/flup/server/fcgi_base.py", line 1118, in handler 
    File "/home/user/lib/python2.4/site-packages/django/core/handlers/wsgi.py", line 230, in __call__ 
    self.load_middleware() 
    File "/home/user/lib/python2.4/site-packages/django/core/handlers/base.py", line 33, in load_middleware 
    for middleware_path in settings.MIDDLEWARE_CLASSES: 
    File "/home/user/lib/python2.4/site-packages/django/utils/functional.py", line 269, in __getattr__ 
    self._setup() 
    File "/home/usr/lib/python2.4/site-packages/django/conf/__init__.py", line 40, in _setup 
    self._wrapped = Settings(settings_module) 
    File "/home/user/lib/python2.4/site-packages/django/conf/__init__.py", line 75, in __init__ 
    raise ImportError, "Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e) 
ImportError: Could not import settings 'settings.py' (Is it on sys.path? Does it have syntax errors?): No module named settings.py 
Content-Type: text/html 



Unhandled Exception 

Unhandled Exception

An unhandled exception was thrown by the application.

我在做什麼錯?

從瀏覽器運行腳本只是給我一個內部服務器錯誤。

回答

3

os.environ['DJANGO_SETTINGS_MODULE'] = "settings.py" 

應該更像

os.environ['DJANGO_SETTINGS_MODULE'] = "settings" 

根據你如何設置sys.path。該環境變量應該包含模塊的路徑,因爲它應該由Python導入,而不是模塊的實際文件名。

基本上,你有現在的方法是制定Django的做這樣的事情在內部:

import settings.py 

即,它試圖從settings模塊內部導入py模塊。