[Fixed]-Django 'TestForm' object has no attribute 'fields'

33👍

You need to call super first, so that the superclass sets up the fields attribute.

def __init__(self, *args, **kwargs):                                         
    testlist = kwargs.pop('testlist', None)
    log.info(regionlist)
    super(TestForm, self).__init__(*args, **kwargs)
    self.fields['testlist'] = forms.ChoiceField(choices=testlist)        

Leave a comment