Could anyone explain to me similarities and differences of Django’s forms.Form & forms.ModelForm?
Could anyone explain to me similarities and differences of Django’s forms.Form & forms.ModelForm ?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Forms created from
forms.Formare manually configured by you. You’re better off using these for forms that do not directly interact with models. For example a contact form, or a newsletter subscription form, where you might not necessarily be interacting with the database.Where as a form created from
forms.ModelFormwill be automatically created and then can later be tweaked by you. The best examples really are from the superb documentation provided on the Django website.forms.Form:Documentation: Form objects
Example of a normal form created with
forms.Form:forms.ModelForm:Documentation: Creating forms from models
Straight from the docs:
Example of a model form created with
forms.Modelform:This form automatically has all the same field types as the
Articlemodel it was created from.