您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Django表单和Bootstrap-CSS类和<divs>

Django表单和Bootstrap-CSS类和<divs>

我喜欢使用“ django-crispy-forms”,它是django-uni-form的后继版本。这是一个很棒的小API,并且对Bootstrap有很好的支持

当需要对渲染进行更多控制时,我倾向于使用模板过滤器来快速移植旧代码快速表单以及模板标签

这是我想出的:

<form class="form-horizontal" method="post">{% csrf_token %}
    <fieldset>
        <legend>{{ title }}</legend>
        {% for field in form %}
            {% if field.errors %}
                <div class="control-group error">
                    <label class="control-label">{{ field.label }}</label> 
                    <div class="controls">{{ field }}
                        <span class="help-inline">
                            {% for error in  field.errors %}{{ error }}{% endfor %}
                        </span>
                    </div>
                </div>
            {% else %}
                <div class="control-group">
                    <label class="control-label">{{ field.label }}</label> 
                    <div class="controls">{{ field }}
                        {% if field.help_text %}
                            <p class="help-inline"><small>{{ field.help_text }}</small></p>
                        {% endif %}
                    </div>
                </div>
            {% endif %}
        {% endfor %}
    </fieldset>
    <div class="form-actions">
        <button type="submit" class="btn btn-primary" >Submit</button>
    </div>
</form>
CSS 2022/1/1 18:22:28 有322人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶