开发者

Settings module not found deploying django on a shared server

开发者 https://www.devze.com 2022-12-24 14:58 出处:网络
I\'m trying to deploy my django project on a shared hosting as describe here I have my project on /home/user/www/testa

I'm trying to deploy my django project on a shared hosting as describe here

I have my project on /home/user/www/testa

I'm using this script


#!/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.fa开发者_如何学运维stcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")

And here's the error I get when trying to run it from 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.

What am I doing wrong?

Running the script from the browser just gives me an internal server error.


The line

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

should be more like

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

based on how you're setting up sys.path. That environment variable is supposed to contain the path to the module as it should be imported by Python, not the actual filename of the module.

Basically, the way you've got it now is making Django do something like this internally:

import settings.py

I.e., it's trying to import a py module from inside a settings module.

0

精彩评论

暂无评论...
验证码 换一张
取 消