使用django 1.6应用程序在apache 2.4和python 3.3上运行mod_wsgi时出现错误500

时间:2014-01-10 06:15:05

标签: python django apache mod-wsgi

在过去的几个月里,我一直在为我现在的雇主编写一个django-app,他们现在想把它部署到服务器上。我知道有很多关于这个问题的线索,但没有一个帮我解决这个问题。

我在Windows 7 PC上使用Python 3.3和Django 1.6以及mod_wsgi。服务器是Apache 2.4通过XAMPP。

在过去的几天里,我尝试将我的应用程序发布到服务器,但它没有用。我认为我取得了一些进展,从一个非功能性的服务器而不是#34;访问被拒绝"我得到服务器错误500的当前状态的错误。我觉得非常接近,但是我现在完全陷入困境并需要一些帮助。

这是我的httpd.conf的一部分:

WSGIPythonPath "C:/TSDE_Workarea/Kmg1yh/SharCC/Workspaces/ReservationTool/PythonReDesign/trunk"
WSGIPythonHome "C:/TSDE_Workarea/Kmg1yh/SharCC/Workspaces/ReservationTool/PythonReDesign/trunk"
WSGIScriptAlias / "C:/TSDE_Workarea/Kmg1yh/SharCC/Workspaces/ReservationTool/PythonReDesign/trunk/PythonReDesign/wsgi.py"

<Directory "C:/TSDE_Workarea/Kmg1yh/SharCC/Workspaces/ReservationTool/PythonReDesign/trunk/PythonReDesign">
    <Files wsgi.py>
        #Options Indexes FollowSymLinks Includes ExecCGI
        Order allow,deny
        Allow from all
        #Require all granted
    </Files>
    DirectoryIndex wsgi.py
</Directory>

我的wsgi.py看起来像这样(只是django在开始一个新项目时创建的基本内容。我尝试向wsgi.py添加新路径,但它没有改变任何东西。):

"""
WSGI config for PythonReDesign project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/
"""

import os, sys
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "PythonReDesign.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

现在当我启动服务器并尝试访问该页面时,我得到了臭名昭着的500错误。 apache错误日志给出了以下错误:

[Fri Jan 10 15:08:40.017397 2014] [:error] [pid 6676:tid 1876] [client 127.0.0.1:61162] mod_wsgi (pid=6676): Target WSGI script 'C:/TSDE_Workarea/Kmg1yh/SharCC/Workspaces/ReservationTool/PythonReDesign/trunk/PythonReDesign/wsgi.py' cannot be loaded as Python module.
[Fri Jan 10 15:08:40.017397 2014] [:error] [pid 6676:tid 1876] [client 127.0.0.1:61162] mod_wsgi (pid=6676): Exception occurred processing WSGI script 'C:/TSDE_Workarea/Kmg1yh/SharCC/Workspaces/ReservationTool/PythonReDesign/trunk/PythonReDesign/wsgi.py'.
[Fri Jan 10 15:08:40.017397 2014] [:error] [pid 6676:tid 1876] [client 127.0.0.1:61162] Traceback (most recent call last):\r
[Fri Jan 10 15:08:40.017397 2014] [:error] [pid 6676:tid 1876] [client 127.0.0.1:61162]   File "C:/TSDE_Workarea/Kmg1yh/SharCC/Workspaces/ReservationTool/PythonReDesign/trunk/PythonReDesign/wsgi.py", line 13, in <module>\r
[Fri Jan 10 15:08:40.017397 2014] [:error] [pid 6676:tid 1876] [client 127.0.0.1:61162]     from django.core.wsgi import get_wsgi_application\r
[Fri Jan 10 15:08:40.017397 2014] [:error] [pid 6676:tid 1876] [client 127.0.0.1:61162] ImportError: No module named 'django'\r

我真的被困在这里,它让我疯了。任何帮助将不胜感激!提前谢谢!

编辑:

省略PythonHome时的错误日志:

[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683] mod_wsgi (pid=5288): Exception occurred processing WSGI script 'C:/TSDE_Workarea/Kmg1yh/SharCC/Workspaces/ReservationTool/PythonReDesign/trunk/PythonReDesign/wsgi.py'.
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683] Traceback (most recent call last):\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]   File "C:\\Python33\\lib\\site-packages\\django\\core\\urlresolvers.py", line 339, in urlconf_module\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]     return self._urlconf_module\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683] AttributeError: 'RegexURLResolver' object has no attribute '_urlconf_module'\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683] \r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683] During handling of the above exception, another exception occurred:\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683] \r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683] Traceback (most recent call last):\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]   File "C:\\Python33\\lib\\site-packages\\django\\core\\handlers\\base.py", line 101, in get_response\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]     resolver_match = resolver.resolve(request.path_info)\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]   File "C:\\Python33\\lib\\site-packages\\django\\core\\urlresolvers.py", line 318, in resolve\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]     for pattern in self.url_patterns:\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]   File "C:\\Python33\\lib\\site-packages\\django\\core\\urlresolvers.py", line 346, in url_patterns\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]     patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]   File "C:\\Python33\\lib\\site-packages\\django\\core\\urlresolvers.py", line 341, in urlconf_module\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]     self._urlconf_module = import_module(self.urlconf_name)\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]   File "C:\\Python33\\Lib\\importlib\\__init__.py", line 90, in import_module\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]     return _bootstrap._gcd_import(name[level:], package, level)\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]   File "<frozen importlib._bootstrap>", line 1584, in _gcd_import\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]   File "<frozen importlib._bootstrap>", line 1565, in _find_and_load\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]   File "<frozen importlib._bootstrap>", line 1532, in _find_and_load_unlocked\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]   File "<frozen importlib._bootstrap>", line 584, in _check_name_wrapper\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]   File "<frozen importlib._bootstrap>", line 1022, in load_module\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]   File "<frozen importlib._bootstrap>", line 1003, in load_module\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]   File "<frozen importlib._bootstrap>", line 560, in module_for_loader_wrapper\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]   File "<frozen importlib._bootstrap>", line 868, in _load_module\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]   File "<frozen importlib._bootstrap>", line 313, in _call_with_frames_removed\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]   File "C:\\TSDE_Workarea\\Kmg1yh\\SharCC\\Workspaces\\ReservationTool\\PythonReDesign\\trunk\\PythonReDesign\\urls.py", line 6, in <module>\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]     from PythonReDesign.views import *\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]   File "C:\\TSDE_Workarea\\Kmg1yh\\SharCC\\Workspaces\\ReservationTool\\PythonReDesign\\trunk\\PythonReDesign\\views.py", line 9, in <module>\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]     import PythonReDesign.commons as com\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683] ImportError: No module named 'PythonReDesign.commons'\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683] \r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683] During handling of the above exception, another exception occurred:\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683] \r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683] Traceback (most recent call last):\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]   File "C:\\Python33\\lib\\site-packages\\django\\core\\handlers\\wsgi.py", line 206, in __call__\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]     response = self.get_response(request)\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]   File "C:\\Python33\\lib\\site-packages\\django\\core\\handlers\\base.py", line 196, in get_response\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]     response = self.handle_uncaught_exception(request, resolver, sys.exc_info())\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]   File "C:\\Python33\\lib\\site-packages\\django\\core\\handlers\\base.py", line 231, in handle_uncaught_exception\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]     return debug.technical_500_response(request, *exc_info)\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]   File "C:\\Python33\\lib\\site-packages\\django\\views\\debug.py", line 69, in technical_500_response\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]     html = reporter.get_traceback_html()\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]   File "C:\\Python33\\lib\\site-packages\\django\\views\\debug.py", line 323, in get_traceback_html\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]     c = Context(self.get_traceback_data())\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]   File "C:\\Python33\\lib\\site-packages\\django\\views\\debug.py", line 281, in get_traceback_data\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]     frames = self.get_traceback_frames()\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]   File "C:\\Python33\\lib\\site-packages\\django\\views\\debug.py", line 428, in get_traceback_frames\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]     pre_context_lineno, pre_context, context_line, post_context = self._get_lines_from_file(filename, lineno, 7, loader, module_name)\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]   File "C:\\Python33\\lib\\site-packages\\django\\views\\debug.py", line 379, in _get_lines_from_file\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]     source = loader.get_source(module_name)\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683]   File "<frozen importlib._bootstrap>", line 605, in _requires_frozen_wrapper\r
[Fri Jan 10 16:23:06.296711 2014] [:error] [pid 5288:tid 1868] [client 127.0.0.1:61683] ImportError: importlib._bootstrap is not a frozen module\r

3 个答案:

答案 0 :(得分:3)

问题是您的PATH上没有site-packages。我们来看看WSGIPythonHome这一行。 According to the mod_wsgi documentation,此配置指令用于(强调我的):

  

用于向Python初始化时指示其    已安装文件。这应该在Python的位置定义   可执行文件不在Apache运行的用户的PATH中,或   系统中有多个版本的Python安装在不同的版本中   文件系统中的位置,尤其是不同的安装   相同的主要/次要版本,以及Apache找到的安装   

中的PATH不是理想的

换句话说,如果你的服务器有多个python安装并且你担心会让它们混淆,那就太好了。但正如你在部分评论中提到的,你没有使用virtualenv。所以没有必要使用该指令。有了它,你实际上做的是误导apache在错误的位置寻找python库,这意味着它找不到模块django。删除它解决了这个问题

至于发生的第二个问题,它可能需要一些挖掘,因为它似乎与你自己的模型有关,并且可能与apache无关。运行devserver有助于找到那些并更容易处理它们。祝你好运!

答案 1 :(得分:0)

您可以尝试使用\ n替换wsgi.py中行尾的\ r吗?你的apache和mod_wsgi设置没有问题。如果使用notepad ++,则可以启用查看所有空格字符。

答案 2 :(得分:0)

由于错误消息显示它找不到django,我怀疑这是一个虚拟问题。你在虚拟环境中安装了django吗?

如果是这样,请确保网站包也在您的路径中as mentioned in the Django docs

相关问题