我正在尝试从基类 UserCreationForm 创建注册表单,在 django 中添加电子邮件字段。代码如下
表格.py
class ussignup(UserCreationForm):
email=forms.EmailField(required=True)
first_name=forms.CharField(required=False)
last_name=forms.CharField(required=False)
class Meta:
model=User
fields=('username','password1','password2','first_name','last_name','email',)
#fields=('username','password','first_name','last_name','email')
def save(self, commit=True):
user = super(UserCreationForm, self).save(commit=False)
user.email=self.cleaned_data["email"]
user.first_name=self.cleaned_data["first_name"]
user.last_name=self.cleaned_data["last_name"]
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']=form
return render_to_response('register.html',args)
网址.py
url(r'^accounts/signup',signup),
错误
输出显示表单,但在字段中输入的密码未保存在数据库中。因此no password
从管理员查看时显示,因此无法登录。