【问题标题】:Django BooleanField does not display labelDjango BooleanField 不显示标签
【发布时间】:2013-07-06 05:43:09
【问题描述】:

我正在摆弄 Django 表单和 Django Crispy Forms(使用 Bootstrap 作为我的主题)。我定义了两个字段:

test1 = forms.BooleanField(label='Some label here', help_text='help text here')

test2 = forms.CharField(label='another label', help_text='more help text')

当我呈现表单时,test2 字段显示如下标签:

another label: <input box>

下面有“更多帮助文本”。

但是,对于test1(BooleanField),标签似乎改变了文本框后显示的值,即

[] 'Some label here'
help text here

有没有办法让它显示得更像:

Some label here []
help text here

谢谢!

【问题讨论】:

  • 这就是你要找的东西:stackoverflow.com/a/2045308/1628832
  • 我看了那个例子,但我不确定如何使它与 Crispy Forms 一起工作,因为我的模板只包含以下内容:{% block content %} {% crispy form %} { % 端块 %}

标签: django django-forms django-crispy-forms


【解决方案1】:

我最终为某些字段使用了自定义模板,例如:

Field('my_field', template='my_field_template.html')

在 my_field_template.html 中,我可以指定我想要的顺序。

【讨论】:

    猜你喜欢
    • 2016-04-17
    • 2017-06-01
    • 1970-01-01
    • 2014-05-16
    • 2019-02-22
    • 1970-01-01
    • 1970-01-01
    • 2021-06-07
    • 2016-05-18
    相关资源
    最近更新 更多