我正在使用
RegistrationForm
自定义 django-registration-redux
中的 django-crispy-forms
。为此,我定义了一个工作正常的FormHelper
:
class MyRegistrationForm(RegistrationForm):
def __init__(self, *args, **kwargs):
super(MyRegistrationForm, self).__init__(*args, **kwargs)
helper = self.helper = FormHelper()
# Moving field labels into placeholders
layout = helper.layout = Layout()
for field_name, field in self.fields.items():
layout.append(Field(field_name, placeholder=field.label))
helper.template_pack = 'bootstrap3'
helper.form_show_labels = False
我的表单按我想要的方式显示:没有标签、bootstrap3 和从标签派生的占位符。
Field
定义的 help_text。有一个以某种方式相关的标志here(help_text_inline
),但这并不是为了禁用帮助文本的显示。我在 FormHelper
documentation 中找不到完全禁用帮助文本显示的标志。这有可能吗?
从
Field
定义中删除帮助文本并不是一个真正的选择,因为我继承了 RegistrationForm
并且我不想对其进行太多修改。
下面的代码应该可以解决问题。
def __init__(self, *args, **kwargs):
...
for field_name, field in self.fields.items():
self.fields[fieldname].help_text = None
...
解决方案的灵感来自这个答案这里。