Beispiel #1
0
class UserCreationForm(forms.ModelForm):
    """创建用户的表单"""
    username = forms.CharField(max_length=30,
                               required=True,
                               help_text='Required.')
    first_name = forms.CharField(max_length=30,
                                 required=True,
                                 help_text='Optional.')
    last_name = forms.CharField(max_length=30,
                                required=True,
                                help_text='Optional.')
    email = forms.EmailField(
        max_length=254,
        required=True,
        help_text='Required. Inform a valid email address.')
    password1 = forms.CharField(label='password', widget=forms.PasswordInput)
    password2 = forms.charField(label='Password Confirmation',
                                widget=forms.PasswordInput)  # 确认密码

    class Meta:
        #注册表单字段
        model = User
        fields = (
            'username',
            'first_name',
            'last_name',
            'email',
            'password1',
            'password2',
        )

    def clean_password(self):
        #检查两次密码是否相同
        password1 = self.cleaned_data.get('password1')
        password2 = self.cleaned_data.get('password2')
        if password1 and password2 and password1 != password2:
            raise forms.ValidationError("Passwords don't match.")
        return password2

    def save(self, commit=True):
        #以哈希格式存储密码
        user = super().save(commit=False)
        user.set_password(self.cleaned_data['password1'])
        if commit:
            user.save()
        return user
Beispiel #2
0
class JoinForm(forms.Form):
	fullName = forms.CharField(max_length = 100)
	email = forms.charField(max_leng = 100)
	password = forms.CharField(widget = forms.PasswordInput())
Beispiel #3
0
class EmpForm(forms.Form):
    Name= forms.charField()
    Salary = forms.integerField()
class UploadFileForm(forms.Form):
    title = forms.charField(max_length=50)
    file = forms.FileField()
Beispiel #5
0
class JoinForm(forms.Form):
    fullName = forms.CharField(max_length=100)
    email = forms.charField(max_length=100)
    password = forms.CharField(max_length=100)
    retypePassword = form.CharField(max_length=100)
Beispiel #6
0
class healthCareForm(forms.Form):

    today_health_history = forms.charField(label='Your name name',
                                           max_length=7)
Beispiel #7
0
class SearchForm(forms.Form):
    query = forms.charField(label=u'Enter a keyword to search for',
                            widget=forms.TextInput(attrs={'size': 32}))
Beispiel #8
0
class UserForm(forms.ModelForm):
    password = forms.charField(widget=forms.PasswordInput())

    class Meta():
        model = User
        fields = ('username', 'password', 'email')
Beispiel #9
0
class LoginForm(forms.Form):
    username = forms.charField()
    pwd = forms.charField(widget=forms.PasswordInput)