Vikram Vikram - 2 months ago 11
Python Question

Django PasswordInput is printing object instead of form field

I am trying to create my own authentication system by making use of Django Auth module. The problem is when I print my form in the template, Username and text field is displaying fine but the password field its displaying object something like this

<django.forms.widgets.PasswordInput object at 0x00000000039E1710>


Here is my form

class UserLoginForm(forms.Form):
username = forms.CharField(required = True)
password = forms.PasswordInput(render_value = True)


And the template goes here.

{% if form.errors %}
<p>Your username and password didn't match. Please try again.</p>
{% endif %}

<form method="post" action="/portal/login">
{% csrf_token %}
<table>
<tr>
<td>{{ form.username.label_tag }}</td>
<td>{{ form.username }}</td>
</tr>
<tr>
<td>{{ form.password.label_tag }}</td>
<td>{{ form.password }}</td>
</tr>
</table>

<input type="submit" value="login" />
<input type="hidden" name="next" value="{{ next }}" />
</form>


Some one help me on this

-Vikram

Answer

change

password = forms.PasswordInput(render_value = True)

to

password = forms.CharField(widget=forms.PasswordInput(render_value = True))
Comments