How to set password show/hide eye button in Django form

Viewed 3885

First, I will try to solve this problem using native HTML and jquery, but I want to solve this problem in Django form without any script.

I will try this source code.

My expected output is put this same example in the above link to Django form.

1 Answers
class CustomerLoginFrom(ModelForm):
    class Meta:
        model = UserLogin
        fields = ['user_name','password']
        labels = {
            "user_name": "*Username",
            "password": "*Password"
        }    
        widgets = {
            "user_name":  TextInput(attrs={'placeholder':'ex:test','autocomplete': 'off'}), 
            "password": PasswordInput(attrs={'placeholder':'********','autocomplete': 'off','data-toggle': 'password'}),
        }

<input type="password" id="password" name="password" class="form-control" data-toggle="password">

Django password field to add HTML attributes directly to Django form attrs, it works for me.

Related