[英]Error 500 with django 1.6 app running on apache 2.4 and python 3.3 with mod_wsgi
在過去的幾個月中,我一直在為我當前的雇主編寫django-app,現在他們希望將其部署到服務器上。 我知道關於這個問題有很多線程,但是沒有一個線程幫助我解決了這個問題。
我在Windows 7 PC上將Python 3.3與Django 1.6和mod_wsgi一起使用。 該服務器是通過XAMPP的Apache 2.4。
在過去的幾天里,我嘗試將我的應用發布到服務器上,但沒有成功。 我認為我已經取得了一些進展,從無法正常工作的服務器通過“訪問被拒絕”錯誤變為服務器錯誤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
問題是您的PATH上沒有站點包。 讓我們看一下WSGIPythonHome行。 根據mod_wsgi文檔 ,此配置指令用於(強調我的):
用於在初始化時向Python指示其庫 文件的安裝位置 。 應該在Python可執行文件不在Apache所運行用戶的PATH中,或者系統在文件系統中的不同位置(尤其是同一主/次版本的不同安裝)中安裝了多個Python版本的系統中定義此文件,並且Apache在其PATH中找到的安裝不是所需的
換句話說,如果您的服務器上安裝了多個python,那會很好,而且您擔心它會使它們混淆。 但是,正如您在部分評論中提到的那樣,您沒有使用virtualenv。 因此,無需使用該指令。 有了它,您實際上正在做的是誤導apache在錯誤的位置查找python庫,這意味着它找不到django模塊。 刪除它可以解決該問題
至於發生的第二個問題,可能需要花一些時間來挖掘,因為它似乎與您自己的模型有關,並且可能與apache無關。 運行devserver有助於發現問題並更輕松地進行處理。 祝好運!
您可以嘗試將wsgi.py中行尾的\\ r替換為\\ n嗎? 您的apache和mod_wsgi設置沒有問題。 如果您使用的是notepad ++,則可以啟用所有空白字符的查看。
由於錯誤消息說它找不到django
,因此我懷疑這是一個virtualenv問題。 您是否在虛擬環境中安裝了django?
如果是這樣,請確保站點包和Django docs中提到的一樣在您的路徑中 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.