我一直在想,爲什麼當我設置我的django項目'arvindemo'的settings.py debug = False並將其部署到Apache與mod_wsgi,我得到了500內部服務器錯誤。Django:TypeError:'str'對象不可調用,referer:http:// xxx
ENV: Django的1.4.0 的Python 2.7.2 mod_wsgi的2.8 OS的CentOS
這裏是回顧: 瀏覽網頁,去子頁面A/B/C/d,並填寫一些表單,然後將其提交給Apache服務器。 「一旦點擊」提交「按鈕,我將得到'500內部服務器錯誤',以及下面列出的error_log(回溯):
」對不起,我把錯誤的引用,這裏是真正的Traceback應該列出「: PS: ‘計算器不要讓我放置超過2個超鏈接’=‘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
[請替換「計算器不要讓我把更多THAN 2超鏈接'與'http://58.215.177.34/Presentation'] :)
當使用django runserver時,我設置了arvindemo.settings debug =沒錯,一切都好。但是一旦我設置debug = False,事情就會改變。
這裏是我的views.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 , 一切安好。
任何人都可以幫忙嗎?
問候
所有這些文字都需要縮短爲相關信息。我希望看到您的settings.py的片段與發生崩潰時的情況相同。此外,由於您知道導致崩潰的確切URL,因此相關的url信息應該是「Presentation」以及「templatePresentation」視圖。需要看到這個觀點(不是其他的東西)。 – jdi 2012-04-12 17:03:23
事實上,問題不僅出現在「演示文稿」中,當我訪問其他網站時,問題仍然存在(下面是概述:訪問主頁,轉到子頁面A/B/C/D,並填寫一些表單,然後提交給Apache服務器,一旦點擊「提交」按鈕,我就會得到'500內部服務器錯誤'),當我提交表單時出現「500頁」,相關的視圖是「submitPage」,我認爲導致崩潰的確切URL是「http://58.215.177.34/submitPage」。現在這裏是我的設置片段: – user705415 2012-04-13 07:59:13
沒有看到崩潰的正確回溯,並知道代碼的哪部分崩潰,我們真的沒有太多的人能夠幫助。如果您確信崩潰正在發生在您的'submitPage'視圖中,那麼我會建議將遍佈它的打印語句調查值,並檢查開發服務器輸出中的輸出。 – jdi 2012-04-13 16:39:07