โ† All Django Flashcard Decks

Django Forms & Validation Flashcards

6 cards from real Django practice questions. Tap to flip, then mark Knew It or Still Learning โ€” missed cards come back until you master them.

Read the first 6 Django Forms & Validation flashcards as text
  1. What class do you subclass to create a Django form?

    Answer: forms.Form

    forms.Form is the base class for creating standard Django forms with manually defined fields, separate from any model.

  2. What is a Django ModelForm?

    Answer: A form that automatically generates fields from a Django model

    ModelForm creates form fields based on a model's field definitions, reducing duplication by using the model as the source of truth for field types and validators.

  3. Which method checks if a submitted Django form is valid?

    Answer: form.is_valid()

    is_valid() runs all field-level and form-level validation, populates form.cleaned_data if successful, and returns True or False.

  4. Where is validated form data stored after calling `form.is_valid()`?

    Answer: form.cleaned_data

    form.cleaned_data is a dictionary populated by is_valid() that contains the validated and type-coerced form field values.

  5. How do you define custom validation for a single field in a Django form?

    Answer: Define a method named clean_(self)

    A method named clean_fieldname() is automatically called by is_valid() for that field and can raise ValidationError or return the cleaned value.

  6. What does `form.save()` do on a Django ModelForm?

    Answer: Creates or updates the model instance based on the form's cleaned data

    ModelForm.save() creates a new instance or updates an existing one (if bound to an instance) using the validated cleaned_data.

Written and edited by , founder of Practice Test Geeks, with AI assistance. We have not yet matched this exam's facts to an official source, so confirm fees, dates and rules with the exam body. Editorial policy