1

我正在尝试将 Crispy 表单与 Django-userena 一起使用以使其看起来更好,但是当我将 Crispy 表单标签放入其中时,它会复制表单,

我的代码如下:

{% extends 'userena/base_userena.html' %}
{% load i18n %}
{% load url from future %}
{% load crispy_forms_tags %}
{% block title %}{% trans "Signin" %}{% endblock %}
{% block content %}
<form action="" method="post" class="formholder">
  {% csrf_token %}
  {{ form|crispy }}
  <fieldset>
    <legend>{% trans "Signin" %}</legend>
    {{ form.non_field_errors }}
    {% for field in form %}
    {{ field.errors }}
    {% comment %} Displaying checkboxes differently {% endcomment %}
    {% if field.name == 'remember_me' %}
    <p class="checkbox">
    <label for="id_{{ field.name }}">{{ field }} {{ field.label }}</label>
    </p>
    {% else %}
    <p>
    {{ field.label_tag }}
    {{ field }}
    </p>
    {% endif %}
    {% endfor %}
  </fieldset>
  <input type="submit" value="{% trans "Signin" %}" />
  <p class="forgot-password"><a href="{% url 'userena_password_reset' %}" title="{% trans 'Forgot your password?' %}">{% trans "Forgot your password?" %}</a></p>
  {% if next %}<input type="hidden" name="next" value="{{ next }}" />{% endif %}
</form>
{% endblock %}
4

1 回答 1

0

OP的解决方案。

问题是,{{ form|crispy }} 实际上是在 form.py 文件中创建表单,我所要做的就是从标签中删除所有其他的,只保留 {{ form|crispy }}

这是它的样子:

{% extends 'userena/base_userena.html' %}
{% load i18n %}
{% load url from future %}
{% block title %}{% trans "Signin" %}{% endblock %}
{% block content %}
{% load crispy_forms_tags %}
<form action="" method="post" class="formholder">
  {% csrf_token %}
  <fieldset>
    <legend>{% trans "Signin" %}</legend>
      {{ form|crispy }}
  </fieldset>
  <input type="submit" value="{% trans "Signin" %}" />
  <p class="forgot-password"><a href="{% url 'userena_password_reset' %}" title="{% trans 'Forgot your password?' %}">{% trans "Forgot your password?" %}</a></p>
  {% if next %}<input type="hidden" name="next" value="{{ next }}" />{% endif %}
</div>
</form>
{% endblock %}
于 2018-05-01T16:12:42.753 回答