我正在尝试从基类 UserCreationForm 创建注册表单,在 django 中添加电子邮件字段。代码如下
表格.py
class ussignup(UserCreationForm):
email=forms.EmailField()
class Meta:
model=User
fields=('username','email','password1','password2')
def save(self, commit=True):
user = super(UserCreationForm, self).save(commit=False)
user.email=(self.cleaned_data["email"])
if commit:
user.save()
return user
视图.py
def signup(request):
if request.method=='POST':
form=ussignup(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('/accounts/rgsuc')
args={}
args.update(csrf(request))
args['form']=ussignup()
return render_to_response('register.html',args)
网址.py
url(r'^accounts/signup',signup),
错误 输出显示电子邮件字段。但是,它既没有验证必填字段,也没有将电子邮件字段数据插入到我通过此视频教程尝试的用户数据库表中