我目前工作的团队已经无法在我们的本地开发环境中运行 django 应用程序的 django 开发服务器。环境本身(服务器 2008 虚拟机)是 IIS7 支持的 .net 应用程序与多个 django 应用程序的混合体。
我们需要能够让我们的本地开发环境同时运行所有应用程序,以便于开发和测试。我们已决定转向与 IIS 一起运行的 apache 的完整实例,以更接近我们的生产和测试环境(不同之处当然是 linux/windows 用于 apache 的主机)。
我们已经将 mod_wsgi 和 apache 配置为在本地运行,但是似乎我们没有正确配置 python 或 django 路径,因为在运行时我们的应用程序提示 View 不存在,错误如下:
Could not import reporting.views. Error was: DLL load failed: The specified module could not be found.
django 异常位置显示:
Exception Location: C:\Python27\lib\site-packages\django\core\urlresolvers.py in _get_callback, line 132
因此我们假设这是某种路径问题,但到目前为止我们还无法找出问题所在。
谢谢大家。
LoadModule wsgi_module modules/mod_wsgi.so
WSGIPythonHome X:\PathToApplication\venv\Scripts
<VirtualHost *:8000>
ServerName applicationdomain
ServerAlias applicationapidomain
SetEnv DJANGO_ENV local
WSGIScriptAlias / X:/PathToApplication/apache/django.wsgi
<Directory X:/PathToApplication/ >
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:8001>
ServerName applicationdomain
SetEnv DJANGO_ENV local
SSLEngine on
SSLProtocol all -SSLv2
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW
SSLCertificateFile "C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf\wildcard.crt"
SSLCertificateKeyFile "C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf\wildcard.key"
WSGIScriptAlias / X:/PathToApplication/apache/django.wsgi
<Directory X:/PathToApplication/ >
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
最佳答案
您的问题与编译模块和 mod_wsgi 有关。
来自 Python.org 的 Python 有一个嵌入式 list ,允许它加载 DLL 文件。在编译 C 模块时,python 过去常常将 list 嵌入已编译的模块中,但是自从默认情况下开始剥离它们。这里的问题是 mod_wsgi 包含它自己的 python 解释器,它没有包含 list 文件。
我认为,为了让它工作,您需要使用 MingW 进行编译,将 list 嵌入到 Apache 中,或者更改 python 以将 list 嵌入到您正在编译的模块中。
http://www.mail-archive.com/modwsgi@googlegroups.com/msg06255.html有将 list 嵌入 apache2 的人的回复。
如果我的内存服务于 Python27/Lib/distutils/msvc9compiler.py 的第 680 行左右,应该有一些代码看起来像
try:
# Remove references to the Visual C runtime, so they will
# fall through to the Visual C dependency of Python.exe.
# This way, when installed for a restricted user (e.g.
# runtimes are not in WinSxS folder, but in Python's own
# folder), the runtimes do not need to be in every folder
# with .pyd's.
manifest_f = open(manifest_file)
try:
manifest_buf = manifest_f.read()
finally:
manifest_f.close()
pattern = re.compile(
r"""<assemblyIdentity.*?name=("|')Microsoft\.""" \
r"""VC\d{2}\.CRT("|').*?(/>|</assemblyIdentity>)""",
re.DOTALL)
manifest_buf = re.sub(pattern, "", manifest_buf)
pattern = "<dependentAssembly>\s*</dependentAssembly>"
manifest_buf = re.sub(pattern, "", manifest_buf)
manifest_f = open(manifest_file, 'w')
try:
manifest_f.write(manifest_buf)
finally:
manifest_f.close()
except IOError:
pass
删除或注释掉它应该会阻止 python 剥离 list 文件。
关于python - Windows上本地django开发如何配置apache和mod_wsgi,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6538216/