view admission.views.UpdateEducation 未返回 HttpResponse 对象。它返回了无



这是什么问题....

View.Py

def UpdateEducation(request, id=None):
context = {}
user_obj = request.user
if not user_obj.is_authenticated:
return redirect('login')

user_id = Applicant.objects.filter(app_id = user_obj.app_id).first()
applicant = ProfileInfo.objects.filter(user=user_id).first()
if request.POST:
form = EducationForm(request.POST, instance=applicant)
if form.is_valid():
obj = form.save(commit=False)
obj.applicant_info = applicant
obj.save()
return redirect('profile')
else:
context['education_form'] = form
else:
try:
user_info = ApplicantEducation.objects.filter(applicant_info = applicant).get()
form = EducationForm(
initial={
'institute_name': user_info.institute_name,
'marks_percentage' : user_info.marks_percentage,
'affilation_with' : user_info .affilation_with,
'date_completion':user_info.date_completion,
'degree_details' : user_info.degree_details,
}
)
context['education_form']= form
except:
form = EducationForm()
context['education_form']= form
return render(request, 'admission/signup.html', context)

我有一个模型叫applicanteeducation其中我使用教育形式。上面列出的这个视图函数旨在存储教育细节,但它出现了错误。这里缺少什么,请看....

Django视图应该返回一个HTTPResponse对象的实例。目前,如果表单无效,视图不会返回任何内容(else块在第17行)。我认为你需要像这样取消你的返回语句的缩进:

def UpdateEducation(request, id=None):
# ...
if request.POST:
form = EducationForm(request.POST, instance=applicant)
if form.is_valid():
obj = form.save(commit=False)
obj.applicant_info = applicant
obj.save()
return redirect('profile')
else:
context['education_form'] = form
else:
try:
# ...
except:
form = EducationForm()
context['education_form']= form
return render(request, 'admission/signup.html', context)  # <- unindented

相关内容

  • 没有找到相关文章

最新更新