这是我在Django应用程序中的forms.py。但是我还不了解save()函数,尤其是commit关键字。我从博客中获取了此代码。在这里,编写者正在制作用户注册表格。
from django import forms
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
from . models import Document
class NewUserForm(UserCreationForm):
email = forms.EmailField(required=True)
class Meta:
model = User
fields = ("username", "email", "password1", "password2")
def save(self, commit = True):
user = super(NewUserForm, self).save(commit = False)
user.email = self.cleaned_data["email"]
if commit:
user.save()
return user
请说明整个保存功能。