What is the difference between Forms. Form and Forms.Modelform?

Asked

Viewed 1,004 times

3

Hello, dear people.

With the help of a tutorial, I was able to create a template with form and use Forms.Modelform to save in the database, but I saw in the Django documentation that there is also Forms.Form. What’s the difference?

framework Django1.9 Python3.4

2 answers

3


The difference is simple, the Modelform is used to create a Model form.

# Formulário que salva artigos no seu banco de dados.
class ArticleForm(ModelForm):
    class Meta:
        model = Artigo
        fields = ['pub_date', 'headline', 'content', 'reporter']

Already the Form is a common form that has no relation to your database (model).

# formulário de contato para enviar via e-mail
class ContatoForm(forms.Form):
    subject = forms.CharField(max_length=100)
    message = forms.CharField(widget=forms.Textarea)

0

Exactly as it was said above p Modelform connects your Model to the Database, already the Form makes the connection of the Model with the Interface, the Views and Templates.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.