朋友们晚上好。
我正在尝试创建一个易于用户注册的应用程序。使用 Django 1.5,我的问题是用户没有保存在数据库中,我的代码在这里:
#forms.py
class UserCreationForm(forms.ModelForm):
username = forms.RegexField(regex=r'^[\w.@+-]+$',max_length=30,label='Username')
email = forms.EmailField(label="E-mail")
password1 = forms.CharField(widget=forms.PasswordInput,label="Password")
password2 = forms.CharField(widget=forms.PasswordInput,label="Repeat Password")
class Meta:
models = User
fields = ('username','email','password1','password2')
#views.py
from myapp.register.forms import UserCreationForm
class CreateUser(FormView):
template_name = 'registration/registration_form.html'
success:url = '/'
form_class = UserCreationForm
def is_valid(self, form):
user = User.objects.create_user(form.cleaned_data['username'],
form.cleaned_data['email'],
form.cleaned_data['password1'])
#user.save()
return super(CreateUser, self).form_valid(form)
每次我尝试创建用户时,他们都不会被保存。我究竟做错了什么?
“我正在学习一点英语,请原谅我的错误。谢谢”