我已经看到很多关于SO的答案,但在我的案例中没有一个可行.我的模型表格如下:
class ChangePasswordForm(forms.Form):
current_password = forms.CharField(
max_length=64,
widget=forms.PasswordInput(
attrs={'placeholder': 'Current Password', 'autocomplete': 'off'}))
new_password = forms.CharField(
min_length=6,
max_length=64,
widget=forms.PasswordInput(
attrs={'placeholder': 'New Password', 'autocomplete': 'off'}))
confirm_password = forms.CharField(
min_length=6,
max_length=64,
widget=forms.PasswordInput(
attrs={'placeholder': 'Confirm New Password', 'autocomplete': 'off'}))
仍然在表单上填充了current_password,new_password和confirm_password.我已经检查过Safari和Google Chrome,但我仍然遇到同样的问题.谁能告诉我我做错了什么?
最佳答案 使用现代浏览器,我不相信您将能够实现您正在寻找的行为.根据
Mozilla Developer Network,
… many modern browsers do not support autocomplete=”off” for login
fields.
- if a site sets autocomplete=”off” for a form, and the form includes username and password input fields, then the browser will still offer to remember this login, and if the user agrees, the browser will autofill those fields the next time the user visits this page.
- if a site sets autocomplete=”off” for username and password input fields, then the browser will still offer to remember this login, and if the user agrees, the browser will autofill those fields the next time the user visits this page.
This is the behavior in Firefox (since version 38), Google Chrome (since 34), and Internet Explorer (since version 11).