0

我在这里关注并尝试了许多不同的东西,但我一直坚持让我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 正在工作,因为我有一个响应“Hello World!”的 test.py 脚本。我相信 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()
4

2 回答 2

0
  1. This has nothing to do with Embedded vs Demon mode.

  2. If you're just starting out developing a site, why are you mucking around with Apache? Use the development server via manage.py runserver, that's what it's for.

  3. You haven't shown your project layout, but the error message is showing you that it can't find the Python path brett.app.settings. Do you have a settings.py in c:\wamp\www\brett\app\?

于 2012-06-05T18:41:24.820 回答
0

要查看您是否安装了 django,您可以执行 python(如果它不在您的环境中,它应该是 somwehere 之类的:)C:/pythonXX/python.exe并输入:

import django

此外,对于 python 开发,最好在 django 服务器中使用 build。这可以通过 启动python manage.py runserver。它只会让您少做一件事情来进行配置。它是轻量级的,自动重启和单线程。

于 2012-06-05T18:40:18.557 回答