【问题标题】:Django bootstrapform render field and lable separate in templateDjango引导表单渲染字段和标签在模板中分开
【发布时间】:2018-05-07 04:55:22
【问题描述】:

我正在使用带有 bootstrapform https://github.com/tzangms/django-bootstrap-form 的 Django 2.0.4。我想在我的模板中分别呈现我的字段和标签。

目前我可以使用以下方法渲染该字段:

{% load bootstrap %}

{{ form.fieldname|bootstrap }}

我想找到一种方法将标签的呈现与字段分开,以便我可以在标签旁边插入文本以选择工具提示。有人能指出我实现这一目标的正确方向吗?任何帮助将不胜感激!

【问题讨论】:

    标签: django twitter-bootstrap django-forms


    【解决方案1】:

    尝试以下操作:link 提供更多信息

    {{ form.field_name }} will render the field
    
    {{ form.field_name.label }} will render the label
    
    {{ form.field_name.id_for_label }} the ID
    

    【讨论】:

    • 嗨 Lemayzeur,这仅适用于没有 |bootstrap 标签。如果我沿着这条路线走,我将需要为我应用这种方法的字段应用额外的样式。我希望使用 |bootstrap 标签来实现这一点。
    • {{ form|bootstrap }} # 或与单个字段一起使用 {{ form.<field name>|bootstrap }} - 输出单个字段
    • 是的,这就是我已经拥有的。我正在尝试查看是否可以在仍然使用 |bootstrap 标记 时将 field_name 与 field>name.label 分开
    猜你喜欢
    • 1970-01-01
    • 2020-04-25
    • 2013-10-10
    • 2015-08-19
    • 2016-08-23
    • 2021-09-10
    • 2017-09-15
    • 2015-02-14
    • 1970-01-01
    相关资源
    最近更新 更多