问题描述
有人知道是否有正确的方法来去除酥脆的标签吗?
Does anybody know if there is a correct way to remove labels in a crispy form?
我了解到了:
self.fields['field'].label = ""
但这不是一个很好的解决方案.
But it's not a very nice solution.
推荐答案
您可以编辑field.html
模板: https://github.com /maraujop/django-crispy-forms/blob/dev/crispy_forms/templates/bootstrap/field.html#L7
在您的表单中添加一个FormHelper
属性,以控制标签的呈现并在该模板if
中使用它.自定义FormHelper
属性尚未正式记录,因为我还没有时间,但是我在给我的主题演讲中谈到了它们,以下是幻灯片: https://speakerdeck.com/u/maraujop/p/django-crispy-forms
Add a FormHelper
attribute to your form that controls the label rendering and use it in that template if
. Custom FormHelper
attributes are not yet officially documented, because I haven't had time, but I talked about them in a keynote I gave, here are the slides:https://speakerdeck.com/u/maraujop/p/django-crispy-forms
这篇关于删除Django Crispy表单中的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!