Bootstrap帮助块和Django注册表单help_text

时间:2017-04-27 17:26:48

标签: django twitter-bootstrap

我正在使用django.contrib.auth注册表单并尝试使用Bootstrap为所有字段显示一致的帮助文本。

我在我的Django模板中使用以下代码作为表单上for循环的一部分的帮助文本:

<p class="help-block">{{ field.help_text }}</p>

除了用html标签显示的密码字段的帮助文本外,这种方法还可以。

password field help with tags

为了防止这种情况,我将上面的代码更改为:

<p class="help-block">{{ field.help_text|safe }}</p>

但是现在帮助文本没有被Bootstrap格式化,我猜是因为段落块中的html。

help-block no longer formatting

是否有一个明显的步骤我不知道还是有另外一种方法可以做到这一点?

感谢。

1 个答案:

答案 0 :(得分:0)

好的,迟到的答案,但您可以覆盖表单中的帮助文本,并随意创建。

例如:

class MyRegistrationForm(RegistrationForm):
    def __init__(self, *args, **kwargs):
        super(MyRegistrationForm, self).__init__(*args, **kwargs)
        self.fields['password'].help_text = 'Password help text with whatever tags you want.'
相关问题