[Django]-Dynamically generate django forms

7👍

You can add fields in the form’s __init__ method as follows:

class BankForm(forms.Form):
    name = forms.CharField()

    def __init__(self, *args, **kwargs):
        super(BankForm, self).__init__(*args, **kwargs)
        for i in range(10):
            self.fields['contact_' + str(i)] = forms.CharField()

Leave a comment