***强文本***我已经成功编写了模型和表单文件,但是在传递参数后仍然在视图中显示一些错误,因为在定义self后未定义self,这表明NoneType对象没有属性'is_bound < / p>
from django.shortcuts import render
from .models import personal_data,professional_career
from django.http import HttpResponse
from .form import detail , details2
def cricket_form(request, self=None):
if request.method == 'POST':
form=detail(request.POST)
form=detail2(request.POST)
if detail.is_valid(self) or detail2.is_valid(self):
form.save()
context ={
}
return render(request,"template/createform.html",context)
答案 0 :(得分:1)
错误NoneType
对象没有属性is_bound
是
因为您要在表单类is_valid
上调用detail
方法,而不是detail instance
对象form
对象。
将代码更改为:
form1 = detail(request.POST) # Better to user uppercase class name(Detail)
form2 = detail2(request.POST)
if form1.is_valid() or form2.is_valid():
...