[Fixed]-Trouble understanding basic of Django Forms

1πŸ‘

βœ…

Do I need to call super(MyForm, self).clean() inside β€˜clean’ method of forms.py explicitly, or will it be called automatically once I do

You need to call it explicitly. That is the method which populates the self.errors attribute, when some error is found. Using self.errors you’re just accessing that attribute, not calling any method.

For your second question, it shows KeyError while accessing self.cleaned_data['data'] (in case when you call super clean method), because when a particular key is added to self.errors, it is not added to self.cleaned_data. You need to check the key existence or self.errors first, before accessing any cleaned_data key.

πŸ‘€Rohit Jain

Leave a comment