2014-04-18 1 views
0

나는 양식을 제출 때 HttpResponse에 객체를 반환하지 않습니다에 대한 다음과 같은 오류를 잡하고있다 "는 HttpResponse에 객체를 반환하지 않았습니다"왜 난 정말 이해할 수 없다 : 여기 장고 :보기

Exception Type: ValueError at /contact/addcontact 
Exception Value: The view openshift.contactapplication.views.contact didn't return an HttpResponse object. 

내이다 :

# Create your views here. 
from django.shortcuts import render_to_response, render 
from django.http import HttpResponseRedirect, HttpResponse 

#forms imports 
from contactapplication.forms import applicantsForm 

#model imports 
from contactapplication.models import applicantsModel 

def contact(request): 

if request.method == 'POST': 
    form = applicantsForm(request.POST) 
    if form.is_valid(): 
     clean_form =form.cleaned_data 
     collect = applicantsModel(first_name=clean_form['first_name'], last_name=clean_form['last_name'], 
      linkedin_profile=clean_form['linkedin_profile'], elevator_pitch=clean_form['elevator_pitch'], 
      email=clean_form['email'], phone=clean_form['phone']) 
     collect.save() 
     return HttpResponseRedirect('contactUs/contactUs.html') #the same page, change to thankyou page later 


else: 
    return render(request, 'contactUs/contactUs.html',) 

무엇이 문제 일 수 있습니까? 명확하게 반환 중입니다 HttpResponseRedirect

답변

7

방법이 POST이고 양식이 유효하면 HttpResponseRedirect을 반환합니다. method가 POST가 아니면 render()의 결과를 반환합니다. 이것은 HttpResponse입니다. 여태까지는 그런대로 잘됐다.

그러나 메서드가 POST이고 양식이 유효하지 않은 경우이면 명시 적으로 아무 것도 반환하지 않습니다 (따라서 None이 반환됩니다).

들여 쓰기가 올바르다 고 가정합니다. 질문에 약간 잘못되었습니다. 예 : def 아래의 코드는 들여 쓰여지지 않습니다.

+0

지적 해 주셔서 고맙습니다. 그리고 네, 올바르게 읽었습니다. – ApathyBear