我有基于此功能的视图,但我想基于此代码创建基于类的视图。我是Django的新手,请有人帮助我
def contact(request):
if request.method == 'POST':
cform = ContactForm(request.POST)
if cform.is_valid():
name = request.POST.get('name','')
gender = cform.cleaned_data.get('gender','')
email = request.POST.get('email','')
mobile = request.POST.get('mobile','')
about = request.POST.get('about','')
data = ContactData(
name = name,
gender = gender,
email = email,
mobile = mobile,
about = about
)
data.save()
cform = ContactForm()
return render(request,'contact.html', {'cform':cform})
else:
cform = ContactForm(request.POST)
return render(request,'contact.html',{'cform':cform})