pythondjangodjango-forms

How to disable input history in Django forms?


I'm capturing sensitive information on the main page of my Django project. Is there a way to prevent the previous login info from showing when a user clicks or starts typing in the box?


Solution

  • You can disable autocomplete on such fields by setting the HTML5 autocomplete attribute to off. To achieve this in Django's forms you need to pass additional information to the widget for each input, e.g.:

    class MyForm(forms.Form):
    
        secret = forms.CharField(widget=forms.TextInput(attrs={'autocomplete': 'off'}))