我一直想知道为什么当我设置我的 django 项目 'arvindemo' debug = False 的 settings.py 并使用 mod_wsgi 在 Apache 上部署它时,我得到了 500 Internal Server Error。
环境:Django 1.4.0 Python 2.7.2 mod_wsgi 2.8 OS centOS
回顾一下: 访问首页,进入子页面A/B/C/D,填写一些表格,然后提交给Apache服务器。单击“提交”按钮后,我将收到“500 内部服务器错误”,以及下面列出的 error_log(Traceback):
“对不起,我放错了Trackback,这里应该列出真正的Traceback”:PS:“STACKOVERFLOW DON'T LET ME PUT MORE THAN 2 hyperlinks”=“http://58.215.177.34/Presentation”
[Tue Apr 10 11:03:15 2012] [error] [client 122.198.133.250] mod_wsgi (pid=2973): Exception occurred processing WSGI script '/opt/web/django/wsgi/django.wsgi'., referer: STACKOVERFLOW DON'T LET ME PUT MORE THAN 2 hyperlinks
[Tue Apr 10 11:03:15 2012] [error] [client 122.198.133.250] Traceback (most recent call last):, referer: STACKOVERFLOW DON'T LET ME PUT MORE THAN 2 hyperlinks
[Tue Apr 10 11:03:15 2012] [error] [client 122.198.133.250] File "/opt/python2.7/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 241, in __call__, referer: STACKOVERFLOW DON'T LET ME PUT MORE THAN 2 hyperlinks
[Tue Apr 10 11:03:15 2012] [error] [client 122.198.133.250] response = self.get_response(request), referer: STACKOVERFLOW DON'T LET ME PUT MORE THAN 2 URLs
[Tue Apr 10 11:03:15 2012] [error] [client 122.198.133.250] File "/opt/python2.7/lib/python2.7/site-packages/django/core/handlers/base.py", line 179, in get_response, referer: STACKOVERFLOW DON'T LET ME PUT MORE THAN 2 hyperlinks
[Tue Apr 10 11:03:15 2012] [error] [client 122.198.133.250] response = self.handle_uncaught_exception(request, resolver, sys.exc_info()), referer: STACKOVERFLOW DON'T LET ME PUT MORE THAN 2 hyperlinks
[Tue Apr 10 11:03:15 2012] [error] [client 122.198.133.250] File "/opt/python2.7/lib/python2.7/site-packages/django/core/handlers/base.py", line 228, in handle_uncaught_exception, referer: STACKOVERFLOW DON'T LET ME PUT MORE THAN 2 hyperlinks
[Tue Apr 10 11:03:15 2012] [error] [client 122.198.133.250] return callback(request, **param_dict), referer: STACKOVERFLOW DON'T LET ME PUT MORE THAN 2 URLs
[Tue Apr 10 11:03:15 2012] [error] [client 122.198.133.250] TypeError: 'str' object is not callable, referer: STACKOVERFLOW DON'T LET ME PUT MORE THAN 2 hyperlinks
[请将 'STACKOVERFLOW DON'T LET ME PUT MORE THAN 2 hyperlinks' 替换为 'http://58.215.177.34/Presentation'] :)
使用 django runserver 时,我设置了 arvindemo.settings debug = True,一切正常。但是一旦我设置 debug = False,情况就发生了变化。
这是我的意见.py
from django.http import HttpResponseRedirect
from django.http import HttpResponse, HttpResponseServerError
from django.shortcuts import render_to_response
import datetime, string
from user_info.models import *
from django.template import Context, loader, RequestContext
import settings
def hello(request):
return HttpResponse("hello girl")
def helpPage(request):
return render_to_response('kktHelp.html')
def server_error(request, template_name='500.html'):
return render_to_response(template_name,
context_instance = RequestContext(request)
)
def page404(request):
return render_to_response('404.html')
def submitPage(request):
post = request.POST
Mall = 'goodsName'
Contest = 'ojs'
Presentation = 'addr'
WeatherReport = 'city'
Habit = 'task'
if Mall in post:
return submitMall(request)
elif Contest in post:
return submitContest(request)
elif Presentation in post:
return submitPresentation(request)
elif Habit in post:
return submitHabit(request)
elif WeatherReport in post:
return submitWeather(request)
else:
return HttpResponse(request.POST)
return HttpResponseRedirect('404')
def submitXXX():
.....
def xxxx():
....
这里是 urls.py
from django.conf.urls import patterns, include, url
from views import *
from django.conf import settings
handler500 = 'server_error'
urlpatterns = patterns('',
url(r'^hello/$', hello), # hello world
url(r'^$', homePage),
url(r'^time/$', getTime),
url(r'^time/plus/(\d{1,2})/$', hoursAhead),
url(r'^Ttime/$', templateGetTime),
url(r'^Mall$', templateMall),
url(r'^Contest$', templateContest),
url(r'^Presentation$', templatePresentation),
url(r'^Habit$', templateHabit),
url(r'^Weather$', templateWeather),
url(r'^Help$', helpPage),
url(r'^404$', page404),
url(r'^500$', server_error),
url(r'^submitPage$', submitPage),
url(r'^submitMall$', submitMall),
url(r'^submitContest$', submitContest),
url(r'^submitPresentation$', submitPresentation),
url(r'^submitHabit$', submitHabit),
url(r'^submitWeather$', submitWeather),
url(r'^terms$', terms),
url(r'^privacy$', privacy),
url(r'^thanks$', thanks),
url(r'^about$', about),
url(r'^static/(?P<path>.*)$','django.views.static.serve',{'document_root':settings.STATICFILES_DIRS}),
)
我确定我的 django 项目没有语法错误,因为当我使用 django runserver 时,一切正常。
任何人都可以帮忙吗?
此致