HerrPfister
HerrPfister

Reputation: 67

Crispy-Form layout with list

I am currently building a webapp in django using crispy-forms, and I was wondering, is there a way to create a layout for a form using a list of strings for the field names? Thank you.

Upvotes: 0

Views: 548

Answers (1)

jproffitt
jproffitt

Reputation: 6355

You could do something like this:

list_of_field_names = ['field1', 'field2']

self.helper = FormHelper()
self.helper.layout = Layout(
    Fieldset(
        'first arg is the legend of the fieldset',
        *list_of_field_names
    ),
    ...
)

Upvotes: 2

Related Questions