【发布时间】:2012-06-09 19:13:13
【问题描述】:
我在这里关注并尝试了许多不同的东西,但我坚持让我的settings.py 加载。此外,在我寻找答案的过程中,我了解了“嵌入式”和“守护程序”设置,我担心我要走的设置路径将需要我每次更新代码时都重新启动 Apache。有什么方法可以修复以下设置,以便我可以开始开发 Django 站点?并且不需要每次都重新启动 Apache?
我收到的错误是:
ImportError: Could not import settings 'brett.app.settings' (Is it on sys.path?): No module named brett.app.settings
我知道 python 正在工作,因为我有一个 test.py 脚本,它回显“Hello World!”。我相信 Django 正在工作并且 python 可以找到它,因为上述错误发生在 Django 调用堆栈 (\django\conf\__init__.py) 中。此外,我在sys.path.append 语句中尝试了正斜杠、反斜杠以及目录的每个变体。
安装了什么:
Windows 7 Ultimate x64
WAMP 2.2 x64
Apache 2.2.21
Python 2.7.3 AMD64
mod_wsgi 3.3 AMD64 py2.7 (from http://www.lfd.uci.edu/~gohlke/pythonlibs/)
如何配置:
C:\Windows\System32\drivers\etc\hosts
127.0.0.1 brett.local
C:\wamp\bin\apache\Apache2.2.21\conf\httpd.conf
LoadModule wsgi_module modules/mod_wsgi.so
AddHandler wsgi-script .wsgi .py
Options Indexes FollowSymLinks ExecCGI
<VirtualHost 127.0.0.1>
ServerName brett.local
DocumentRoot "c:/wamp/www/brett"
<Directory "c:/wamp/www/brett">
Order Allow,Deny
Allow from all
</Directory>
WSGIScriptAlias / "c:/wamp/www/brett/apache/apache.wsgi"
<Directory "c:/wamp/www/brett/apache">
Allow from all
</Directory>
</VirtualHost>
C:\wamp\brett\apache\apache.wsgi
import os, sys
sys.path.append('c:\\wamp\\www')
os.environ['DJANGO_SETTINGS_MODULE'] = 'brett.app.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
【问题讨论】:
-
我选择不使用 Django 服务器,因为我无法/还没有找到任何关于配置多个站点和本地 url 的好信息。使用 wamp 时,我喜欢为每个站点设置不同的主机,例如
brett.local、clientA.local等。此外,我真的不喜欢为了让服务器运行而必须在命令行上同时启动 wamp 和某些东西。