如何访问form.email?

How to access form.email?

我希望稍微编辑 django-registration 提供的默认值 password_reset_form.html。当前输出为:

我想删除 'E-mail address:' 标签并在输入框中放置一个 'placeholder' 文本。你怎么能做到这一点?我似乎找不到关于 form.email 或 form.email.errors.

的文档

Password_reset_form.html如下图:

{% extends "registration/registration_base.html" %}
{% load i18n %}

{% block title %}{% trans "Reset password" %}{% endblock %}

{% block content %}
<p>
    {% blocktrans %}
    Forgot your password? Enter your email in the form below and we'll send you instructions for creating a new one.
    {% endblocktrans %}
</p>
<form method="post" action="">
    {% csrf_token %}
    {{ form.email.errors }}
    <p><label for="id_email">{% trans 'E-mail address:' %}</label> {{ form.email }} <input type="submit" value="{% trans 'Reset my password' %}" /></p>
</form>
{% endblock %}


{# This is used by django.contrib.auth #}

您可以使用 this package

因此您的代码将如下所示。

{% extends "registration/registration_base.html" %}
{% load i18n %}

{% load widget_tweaks %}

{% block title %}{% trans "Reset password" %}{% endblock %}

{% block content %}
<p>
    {% blocktrans %}
    Forgot your password? Enter your email in the form below and we'll send you instructions for creating a new one.
    {% endblocktrans %}
</p>
<form method="post" action="">
    {% csrf_token %}
    {{ form.email.errors }}
    <p> {{ form.email|attr:"placeholder:E-mail address:"  }} <input type="submit" value="{% trans 'Reset my password' %}" /></p>
</form>
{% endblock %}


{# This is used by django.contrib.auth #}