Django form 'autocomplete'='off' does not work Django form 'autocomplete'='off' does not work google-chrome google-chrome

Django form 'autocomplete'='off' does not work


With modern browsers, I don't believe you will be able to achieve the behavior you're looking for. According to the 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).


In the Django documentation you will find what you need to solve your problem, I did some tests and it worked perfectly.

Solution found - Django documentation

    from django import forms    class ChangePasswordForm(forms.Form):        password = forms.CharField(label='Password', widget=forms.PasswordInput)        confirmPass = forms.CharField(label='Confirm Password', widget=forms.PasswordInput)        password.widget.attrs.update({'autocomplete':'off', 'maxlength':'32'})        confirmPass.widget.attrs.update({'autocomplete':'off', 'maxlength':'32'})


It can be done by changing 'off' with 'new-password' in all of your fields / widget / attrs / autocomplete. It works for me.

EX :

current_password = forms.CharField(    max_length=64,    widget=forms.PasswordInput(        attrs={'placeholder': 'Current Password', 'autocomplete': 'new-password'}))

Solution found here