我面臨這個異常錯誤,我對此感到困惑,因爲這個方法在類似的系統中工作,感謝任何幫助或指針。非常感謝!Django - view沒有返回HttpResponse對象
異常值:該視圖Project.qna.views.add_vote未返回HttpResponse對象。
def add_vote(request):
if request.method == "POST":
q_id = request.POST['vote_form_q_id']
a_id = request.POST['vote_form_a_id']
vote_value = request.POST['vote_form_value']
ok = False
vote_num = None
name = None
if q_id:
try:
question = Question.objects.get(id=q_id)
question.num_vote += int(vote_value)
question.save()
vote_num = question.num_vote
name = 'Question_'+str(q_id)
ok = True
except Question.DoesNotExist:
pass
elif a_id:
try:
answer = Answer.objects.get(id=a_id)
answer.num_vote += int(vote_value)
answer.save()
vote_num = answer.num_vote
name = 'Answer_'+str(a_id)
ok = True
except Answer.DoesNotExist:
pass
if ok and request.is_ajax:
result = simplejson.dumps({
"vote_num": vote_num,
}, cls=LazyEncoder)
response = HttpResponse(result, mimetype='application/javascript')
response.set_cookie(name, datetime.now)
return response
嘛。如果您的縮進在實際文件中是相同的,那麼它將無法工作,因爲這是一個錯誤的開始。 – aychedee 2012-08-04 10:43:48
提示:當你最後一個「if」失敗時會發生什麼? – 2012-08-04 13:30:18