Django 脆皮表单布局助手不起作用

Django crispy form layout helper does not work

我正在尝试使用 crispy form 的帮助程序和布局来设置我的表单的 html 布局。 换句话说,我按以下方式设置了表单。

class MaterialeForm(forms.ModelForm):
    data_contabile=forms.DateTimeField(widget=DatePicker(attrs={
    class Meta:
        model = Materiale
        fields = "__all__"

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.helper = FormHelper()

        self.layout = Layout(
            Field('conta', id="form-conto", css_class="form-control", name="Conto"))

然后我在模板中设置了 html 代码:

<div class="modal-body">
                  <label for="conto"></label>
                  {{form.conto|as_crispy_field}}

但是在布局中,id 和 name 不能正常工作。事实上,如果我查看页面,我会尝试以下代码:

<select name="conto" class="select form-control form-control" required="" id="id_conto"> <option value="">---------</option> <option value="1" selected="">Materia Prima</option>

</select>

哪里出错了?

我也刚开始使用脆皮表格。试图解决类似的问题,我注意到布局助手仅在使用时有效:

{% crispy form %}

而不是 {{ form|crispy}} 或任何模板过滤器变体。