我有一个定义如下的表格:
from django import forms
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm as DjangoUserCreationForm
class UserEmailForm(DjangoUserCreationForm):
email = forms.EmailField(required=True)
class Meta:
model = User
fields = ("email",)
def save(self, commit=True):
user = super(UserEmailForm, self).save(commit=False)
user.email = self.cleaned_data["email"]
if commit:
user.save()
return user
但是当我尝试显示表单时,它显示了四个字段,用户名、电子邮件、密码1、密码2