Django PasswordInput是打印对象而不是表单字段

时间:2012-09-16 06:05:46

标签: python django forms

我正在尝试使用Django Auth模块创建自己的身份验证系统。问题是当我在模板中打印表单时,用户名和文本字段显示正常但密码字段显示对象类似于此<django.forms.widgets.PasswordInput object at 0x00000000039E1710>

这是我的表格

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

模板就在这里。

{% 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>

有人帮我这个

-Vikram

2 个答案:

答案 0 :(得分:3)

更改

password = forms.PasswordInput(render_value = True)

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

答案 1 :(得分:0)

好的,我得到了答案:在更正这样的表格之后显示正常

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

对不起垃圾邮件

-Vikram