部署django应用程序时出现问题

时间:2015-05-25 19:04:25

标签: python django django-deployment

我得到"内部服务器错误"当我尝试访问django网站时。 我使用的是Django 1.8,Python 2.7.10,centos 6.5和apache。

在apache日志中,我收到以下错误:

mod_wsgi (pid=23866): Target WSGI script '/abc/abc/abc/wsgi.py' cannot be loaded as Python module.
[Mon May 25 14:40:47 2015] [error] [client xyz] mod_wsgi (pid=23866): Exception occurred processing WSGI script '/abc/abc/abc/wsgi.py'.
[Mon May 25 14:40:47 2015] [error] [client xyz] Traceback (most recent call last):
[Mon May 25 14:40:47 2015] [error] [client xyz]   File "/abc/abc/abc/wsgi.py", line 12, in <module>
[Mon May 25 14:40:47 2015] [error] [client xyz]     from django.core.wsgi import get_wsgi_application
[Mon May 25 14:40:47 2015] [error] [client xyz]   File "/abc/lib/python2.7/site-packages/django/__init__.py", line 1, in <module>
[Mon May 25 14:40:47 2015] [error] [client xyz]     from django.utils.version import get_version
[Mon May 25 14:40:47 2015] [error] [client xyz]   File "/abc/lib/python2.7/site-packages/django/utils/version.py", line 7, in <module>
[Mon May 25 14:40:47 2015] [error] [client xyz]     from django.utils.lru_cache import lru_cache
[Mon May 25 14:40:47 2015] [error] [client xyz]   File "/abc/lib/python2.7/site-packages/django/utils/lru_cache.py", line 28
[Mon May 25 14:40:47 2015] [error] [client xyz]      fasttypes = {int, str, frozenset, type(None)},
[Mon May 25 14:40:47 2015] [error] [client xyz]                      ^
[Mon May 25 14:40:47 2015] [error] [client xyz]  SyntaxError: invalid syntax

由于

2 个答案:

答案 0 :(得分:7)

虽然你说你正在运行Python 2.7,但是这个错误表明你实际上使用的是2.6,因为set literals只在2.7中引入。

问题是mod_wsgi是针对特定的Python版本编译的,在你的情况下是Centos 6.5附带的版本。您需要为2.7重新编译它,或者找到已针对该版本编译的版本。

答案 1 :(得分:0)

您需要开始为django项目使用virtualenv。这是一个不错的tutorial。对于临时解决方案,您可以使用python2.7 manage.py runserver使用python 2.7运行django。但是,强烈建议您研究virtualenv。让生活更轻松。

关于使mod_wsgi使用python 2.7,你需要重新编译它。为此,只需下载源并执行:

$ ./configure
$ make
$ sudo make install

他们有快速安装指南,您可以访问here