在 os x 上使用 django 和 mod-wsgi 解决方案的初步步骤
我正在运行 apache / os x 并提供 localhost 页面来在我的笔记本电脑上测试 django。我已经验证了以下所有内容
• python 工作正常并且是最新的 (2.5.1)
• django 可用于 python 并且是最新的 (1,1,0, 'final', 0)
• mod_wsgi 模块已加载到其中我的 apache 配置中的 apache 模块 - 检查!
• django 应用程序的路径位于具有适当权限的vhost.conf 中- 好的!
• mod_wsgi vhost.conf 经过测试,在预期的 django 应用程序目录中工作正常 - 通过 localhost 测试应用程序会显示 200 OK, 'hello world!'
• django 默认应用程序已使用“django-admin.py startproject mysite”创建。
• django 应用程序使用开发服务器在端口 8000 上正常工作 - 好的!
• 新的 django 应用程序(称为 mysite)的路径位于 python 路径上 - 已验证!
所有这些都经过验证,当我使用 DJANGO_SETTINGS_MODULE settings.py 运行 wsgi 脚本并加载 django 应用程序时,我仍然得到“无法导入设置 'mysite.settings' 等”。
由于这似乎涵盖了基本的故障排除,还有更多吗我可以采取哪些步骤来找出问题所在?
================
Python 路径有效,已验证。 django 开发服务器在端口 8000 上使用命令行运行良好。apache
配置已加载典型模块: LoadModule wsgi_module libexec/apache2/mod_wsgi.so
vhost.conf 包含在 apache 配置中,如下所示
NameVirtualHost: *.80
<Directory /users/useracct/scripts/python>
Order allow,deny
Allow from all
</Directory>
<Directory /Library/WebServer/Documents>
Order allow,deny
Allow from all
</Directory>
WSGIDaemonProcess localhost user=username group=staff threads=25
WSGIProcessGroup localhost
WSGIScriptAlias /mysite /users/useracct/Sites/mysite/mysite.wsgi
<Directory /users/useracct/Sites/mysite/>
Allow from all
</Directory>
DocumentRoot /Users/useracct/Sites/
Virtualenv 未使用此帐户设置,因此这是一个不太可能的原因。
=======================
和 wsgi 脚本文件(尽量保持最小):
import os, sys
path = '/users/usracct/sites/mysite'
if path not in sys.path:
sys.path.append(path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
I'm running apache / os x and serving up localhost pages to test django on my laptop. I've already verified all the following
• python is working fine and up to date (2.5.1)
• django available to python and up to date (1,1,0, 'final', 0)
• mod_wsgi module is loaded among apache modules in my apache config - Check!
• path to django application is in vhost.conf with proper permissions - OK!
• mod_wsgi vhost.conf tested and working fine in the intended django application directory
- test application through localhost pulls up 200 OK, 'hello world!'
• django default application has been created using 'django-admin.py startproject mysite'
• django application works fine on port 8000 using development server - OK!
• path to the new django application (called mysite) is on python path - verified!
All this is verified and when I run the wsgi script with DJANGO_SETTINGS_MODULE settings.py and load the django app, I still get 'could not import settings 'mysite.settings' etc.
Since this seems to cover the basic troubleshooting, are there any further steps I could take to find out the problem?
================
Python path is valid, verified. The django development server runs fine with the command line on port 8000.
The apache config has the typical module loaded:
LoadModule wsgi_module libexec/apache2/mod_wsgi.so
vhost.conf is included from apache config as follows
NameVirtualHost: *.80
<Directory /users/useracct/scripts/python>
Order allow,deny
Allow from all
</Directory>
<Directory /Library/WebServer/Documents>
Order allow,deny
Allow from all
</Directory>
WSGIDaemonProcess localhost user=username group=staff threads=25
WSGIProcessGroup localhost
WSGIScriptAlias /mysite /users/useracct/Sites/mysite/mysite.wsgi
<Directory /users/useracct/Sites/mysite/>
Allow from all
</Directory>
DocumentRoot /Users/useracct/Sites/
Virtualenv is not set up with this account, so that is one less possible cause.
=======================
and the wsgi script file (trying to keep it minimal):
import os, sys
path = '/users/usracct/sites/mysite'
if path not in sys.path:
sys.path.append(path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将 /users/useracct/Sites/ a 添加到 wsgi 文件中的 pythonpath 中:
Try adding /users/useracct/Sites/ a to your pythonpath in your wsgi file: