[Fixed]-How form class attributes work in django

1๐Ÿ‘

I think you want to access the form fields in the __init__ method. You should access it from the fields attribute. Like this:

class Test(forms.Form):
    x = forms.CharField(max_length=20)

    def __init__(self, *args, **kwargs):
        super(Test, self).__init__(*args, **kwargs)
        print self.fields['x']

Leave a comment