django表单由浏览器自动填充

时间:2010-09-14 13:58:36

标签: python django forms django-forms

所以我有2个班级

这一个:

class updateForm(forms.Form):
address = forms.CharField(
                        max_length = 255,
                        label      = 'Home Address', 
                        )
cnp    = forms.CharField(
                        max_length = 15,
                        label      = 'CNP',
                        )
phoneNumber = forms.CharField(
                             max_length = 30,
                             label      = 'Phone number',
                             )
token =  forms.CharField(
                        max_length = 20,
                        label      = 'token',
                        )
oldPass = forms.CharField(
                          widget     = forms.PasswordInput,
                          max_length = 30,
                          label      = 'Old Password',
                         )
newPass = forms.CharField(
                          widget     = forms.PasswordInput,
                          max_length = 30,
                          label      = 'New Password',
                         )                                     
retypePass = forms.CharField(
                             widget     = forms.PasswordInput,
                             max_length = 30,
                             label      = 'Retype Password',
                            )

和这一个:

class BaseUsernameForm(forms.Form):
username = forms.CharField(max_length=255,
                           label='Username')
def clean_username(self):
    username = self.cleaned_data['username']
    return _clean_username(username)

class BasePasswordForm(forms.Form):
    password = forms.CharField(max_length=255,
                           widget=forms.PasswordInput,
                           label='Password')

class LoginForm(BaseUsernameForm, BasePasswordForm):
    pass

登录后...并进入updateForm所在的页面...我得到令牌和oldPass字段自动填充令牌:username和oldPass:来自loginForm的密码...为什么?

在html中,他们不共享任何ID或类...我该如何防止这种情况?

1 个答案:

答案 0 :(得分:2)

也许您的浏览器填写了这些值?尝试使用 autocomplete =“OFF”获取令牌和oldPass输入字段,以获得如下内容:

<input type="text" autocomplete="OFF" name="token"/>