Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 782
derrend Avatar asked Aug 05 '16 06:08

derrend


People also ask

What does form AS_P do in Django?

as_p() [Django-doc] is a method on a Form . It produces a SafeText object [Django-doc] that contains HTML code to be included in the template. The fact that it is SafeText is important, since the Django render engine will otherwise "escape" it: without using SafeText , it would replace < with &lt; ; > with &gt; , etc.

What is get and post method in Django?

GET and POSTDjango's login form is returned using the POST method, in which the browser bundles up the form data, encodes it for transmission, sends it to the server, and then receives back its response. GET , by contrast, bundles the submitted data into a string, and uses this to compose a URL.


1 Answers

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'}))
like image 55
solarissmoke Avatar answered Sep 27 '22 22:09

solarissmoke