【发布时间】:2014-09-03 13:30:36
【问题描述】:
我按照教程 Tango with Django 构建了我的 Django 项目。一切运行正常。
文件结构:
tango/
rango/
tango/
wsgi.py
settings.py
manage.py
现在我正在尝试在 CherryPy 服务器上部署项目,遵循this tutorial。 wsgi.py的默认内容如下:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tango.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
现在在与wsgi.py 相同的文件夹中,我创建了server.py:
from wsgi import application
import cherrypy
if __name__ == '__main__':
# Mount the application
cherrypy.tree.graft(application, "/")
# Unsubscribe the default server
cherrypy.server.unsubscribe()
# Instantiate a new server object
serve = cherrypy._cpserver.Server()
# Configure the server object
server.socket_host = "0.0.0.0"
server.socket_port = 8080
server.thread_pool = 30
# Subscribe this server
server.subscribe()
# Start the server engine (Option 1 *and* 2)
cherrypy.engine.start()
cherrypy.engine.block()
我的问题:
如果我在 Eclipse 中运行 server.py(右键单击 server.py --> 运行方式 --> Python 运行),一切正常。但是,如果我在终端中输入命令$ python server.py,则会显示以下错误消息:
Traceback (most recent call last):
File "server.py", line 1, in <module>
from wsgi import application
File "<tangoProject>/tango/wsgi.py", line 14, in <module>
application = get_wsgi_application()
File "<virtualenv>/local/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
django.setup()
File "<virtualenv>/local/lib/python2.7/site-packages/django/__init__.py", line 20, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "<virtualenv>/local/lib/python2.7/site-packages/django/conf/__init__.py", line 46, in __getattr__
self._setup(name)
File "<virtualenv>/local/lib/python2.7/site-packages/django/conf/__init__.py", line 42, in _setup
self._wrapped = Settings(settings_module)
File "<virtualenv>/local/lib/python2.7/site-packages/django/conf/__init__.py", line 98, in __init__
% (self.SETTINGS_MODULE, e)
ImportError: Could not import settings 'tango.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named tango.settings
注意,上面我用<djangoProject>和<virtualenv>分别指定了项目和virtualenv的目录。
似乎服务器找不到tango/settings.py 文件。我该如何解决?
【问题讨论】:
-
您是否已将路径添加到
sys.path?