Django 和 Apache 问题

标签 django apache mod-wsgi

我正在尝试使用 Mod_wsgi 让 Django 和 Apache 一起工作,目前我遇到以下错误:

[Thu Jul 15 12:52:38 2010] [error] [client 10.100.50.73] mod_wsgi (pid=4803): Target WSGI script '/home/webdev/websites/virtualenvs/polaris/polaris_project.py' cannot be loaded as Python module.
[Thu Jul 15 12:52:38 2010] [error] [client 10.100.50.73] mod_wsgi (pid=4803): Exception occurred processing WSGI script '/home/webdev/websites/virtualenvs/polaris/polaris_project.py'.
[Thu Jul 15 12:52:38 2010] [error] [client 10.100.50.73] Traceback (most recent call last):
[Thu Jul 15 12:52:38 2010] [error] [client 10.100.50.73]   File "/home/webdev/websites/virtualenvs/polaris/polaris_project.py", line 8, in <module>
[Thu Jul 15 12:52:38 2010] [error] [client 10.100.50.73]     import django.core.handlers.wsgi
[Thu Jul 15 12:52:38 2010] [error] [client 10.100.50.73] ImportError: No module named django.core.handlers.wsgi

我的 apache conf 看起来像

Alias /polaris_django/media/ "/home/webdev/websites/virtualenvs/polaris/polaris/static/"
WSGIScriptAlias /polaris_django /home/webdev/websites/virtualenvs/polaris/polaris_project.py
WSGIApplicationGroup %{GLOBAL}

<Directory "/home/webdev/websites/virtualenvs/polaris">
        Order deny,allow
        Allow from all
</Directory>

我的 Mod_WSGi 文件看起来像

import os, sys

sys.path.append('/home/webdev/websites/virtualenvs/polaris')
sys.path.append('/home/webdev/websites/virtualenvs/polaris/polaris/apps')
sys.path.append('/home/webdev/websites/virtualenvs/polaris/polaris/extra_settings')
os.environ['DJANGO_SETTINGS_MODULE'] = 'polaris.settings'
print >> sys.stderr, sys.path
import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

如何让 apache 正确地为 Django 服务?

最佳答案

看起来您正在使用 virtualenv - 您需要在 WSGI 脚本中激活它以正确设置路径。

activate_this = os.path.join("path/to/my/virtualenv", "bin/activate_this.py")
execfile(activate_this, dict(__file__=activate_this))

关于Django 和 Apache 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3257979/

相关文章:

python - 如何在 django 中由系统(webSite)自动调用方法?

apache - 访问 Magento 安装时出现 302 响应

尝试在 CentOS 上以守护程序模式配置 Django/mod_wsgi 应用程序时,python-home 选项失败

python - 虚拟环境错误的python版本

python - 按外键计数和分组并返回模型django

django - 表单集中每个表单中字段的不同标签

django - django 在哪里呈现默认的 500 回溯,以便我可以使用它来创建自己的日志?

php - 有没有类似Wamp Server的东西?

c++ - Apache 模块命令解析器原型(prototype)

mod-wsgi - 如何从 WSGI 应用程序返回内存中的 PIL 图像