如何使用django小部件调整呈现django用户创建表单帮助文本列表

时间:2018-07-11 17:57:36

标签: python django django-forms bootstrap-4 django-widget-tweaks

在django中,我使用jinja模板语言和django-widget-tweaks为用户创建表单实现了自定义视图。但是在表单中,密码字段的帮助文本是列表项,它以原始文本的形式呈现。有办法解决这个问题。

here is the image which shows the ul element rendering as raw text

and here is a code

{% extends 'base.html' %} {% block head %}
<title>Register</title>
{% endblock %} {% block body %}
{% load widget_tweaks %}
<div class="fs-container">
<form method='post' class="form-signin">
{% csrf_token %} 
{% for hidden_field in form.hidden_fields %} 
        {{ hidden_field }}
    {% endfor %} 
    {% if form.non_field_errors %}
        <div class="alert alert-danger" role="alert">
            {% for error in form.non_field_errors %} 
                {{ error }}
            {% endfor %}
        </div>
    {% endif %} 
    {% for field in form.visible_fields %}
        <div class="form-group">
            <!-- {{ field.label_tag }}  -->
            {% if form.is_bound %} 
                {% if field.errors %} 
                    {% render_field field class="form-control is-invalid" %}
                    {% for error in field.errors %}
                        <div class="invalid-feedback">
                            {{ error }}
                        </div>
                    {% endfor %} 
                {% else %}
          {% render_field field class="form-control is-valid" placeholder=field.label %}
                {% endif %}
            {% else %} 
                {% render_field field class="form-control" placeholder=field.label %}
            {% endif %}
            {% if field.help_text %}
                <small class="form-text text-muted">{{ field.help_text }}</small>
            {% endif %}
        </div>
    {% endfor %}
<button type="submit" class="btn btn-lg btn-primary btn-block cs-btn">Register</button>
</form>
</div>
{% endblock %}

0 个答案:

没有答案