0
我想用一個formset給脆弱形式的DIV自定義標識。 我試圖在表單佈局中使用forloop.counter,因爲它表示它將在模板呈現中注入,但它不起作用(它只是呈現爲這樣的css_id ='liveprice _ {{forloop.counter}} 「給自定義標識符以django脆皮的形式
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',
),
),
)