尝试将表单数据保存到数据库时出现 AttributeError

时间:2021-03-23 20:36:56

标签: python-3.x forms django-forms

    from django.shortcuts import render
    from .forms import RegisterForm

def register(request):
  if request.method=='POST':
 form=RegisterForm(request.POST)
  if form.is_valid():
   name=form.cleaned_data['username']
password=form.cleaned_data['password']
email=form.cleaned_data['email']
gender=form.cleaned_data['gender']

form.save()

form=RegisterForm()
return render(request, 'form.html', {'form': form})'

当我尝试将数据从表单保存到数据库时,我得到: AttributeError: 'RegisterForm' 对象没有属性 'save'

请有人帮我解决这个问题。

0 个答案:

没有答案