【发布时间】:2015-03-19 06:54:04
【问题描述】:
我想使用表单集为带有 Crispy 表单的 DIV 提供自定义 ID。 我正在尝试在表单布局中使用 forloop.counter,因为它说它将被注入模板渲染但它不起作用(它只是被渲染为 css_id='liveprice_{{forloop.counter}}'
class PrinterMaterialForm(ModelForm):
class Meta:
model = PrinterMaterial
fields = ('material', 'hour_cost', 'gram_cost', 'colors')
def __init__(self, *args, **kwargs):
super(PrinterMaterialForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_tag = False
self.helper.form_class = 'form-inline'
self.helper.field_template = 'bootstrap3/layout/inline_field.html'
self.helper.disable_csrf = True
self.helper.layout = Layout(
Div(
Div(
Div(css_class='col-md-4', css_id='liveprice_{{ forloop.counter }}'),
css_class='row',
),
),
)
【问题讨论】:
标签: django django-crispy-forms