milan milan - 2 months ago 9
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="{{ field.name }}" class="form-control" id="{{ field.id_for_label}}">
</div>
{% endfor %}
</form>


filters.py

from django import template
register = template.Library()

@register.filter('input_type')
def input_type(field):
print('field',field.field.widget.__class__)
return field.field.widget.__class__.__name__


How can i show password in dot?

Answer

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'