milan milan - 1 year ago 80
Python Question

password field is showing password in plain text

I have used django allauth for user registration and login system. I could show the form by simplifying the lines of code using for loop. I got the right field type(TextInput and PasswordInput) for each field too. However the password field which has PasswordInput shows password in plain text. How can i resolve this?

my signup page(account/signup.html)

<form class="signup" id="signup_form" method="post" action="{% url 'account_signup' %}">
{% csrf_token %}
{% for field in form.visible_fields %}
<div class="form-group">
<label for="{{ field.id_for_label}}">{{field.label}}</label>
{{ field.errors.0 }}
<input type="{{field|input_type}}" name="{{ }}" class="form-control" id="{{ field.id_for_label}}">
{% endfor %}

from django import template
register = template.Library()

def input_type(field):
return field.field.widget.__class__.__name__

How can i show password in dot?

Answer Source

You can add class by overriding __init__ method in form class

def __init__(self, *args, **kwargs): 
    super().__init__(*args, **kwargs) 
    self.fields['password'].widget.attrs['class'] = 'form-control'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download