Forms Questions with Answers

9 practice questions on Forms (Django) with answers and step-by-step solutions. Try 9 samples below, then practise all 9 free in the AptiNest app.

Sample questions

Question 1Easy

Which method must return True before you read form.cleaned_data?

  1. validate()
  2. is_valid()
  3. check()
  4. save()

Answer: B. is_valid()

Explanation

is_valid() runs validation and populates cleaned_data.

Step-by-step solution

  1. Bind data.
  2. Call is_valid.
  3. Read cleaned_data.

Why the other options are wrong

  • A. validate() is not a real method; the correct choice is is_valid().
  • C. check() is not a real method; the correct choice is is_valid().
  • D. save needs validity first.

Question 2Easy

Which class builds a form directly from a model's fields?

  1. ModelForm
  2. FormModel
  3. ModelBuilder
  4. AutoForm

Answer: A. ModelForm

Explanation

ModelForm uses Meta.model and fields to generate form fields and a save() method.

Step-by-step solution

  1. Set Meta.model.
  2. Pick fields.

Why the other options are wrong

  • B. FormModel is not a Django class; the correct choice is ModelForm.
  • C. ModelBuilder is not a Django class; the correct choice is ModelForm.
  • D. AutoForm is not a Django class; the correct choice is ModelForm.

Question 3Easy

Which attribute of a ModelForm Meta selects included fields?

  1. columns
  2. fields
  3. include
  4. only

Answer: B. fields

Explanation

Use fields = ['title'] or '__all__'; exclude also exists.

Step-by-step solution

  1. Set fields.
  2. Form built.

Why the other options are wrong

  • A. columns is not a Meta option; the correct choice is fields.
  • C. include is not a Meta option; the correct choice is fields.
  • D. only is not a Meta option; the correct choice is fields.

Question 4Medium

Which method must be called before accessing form.cleaned_data?

  1. save()
  2. clean_all()
  3. is_valid()
  4. render()

Answer: C. is_valid()

Explanation

cleaned_data exists only after validation.

Step-by-step solution

  1. form.cleaned_data is available only after validation.
  2. Validation is done using the is_valid() method.
  3. is_valid() checks all form fields and prepares cleaned_data.
  4. You must call is_valid() before accessing cleaned_data.
  5. Thus, the correct answer is is_valid().

Why the other options are wrong

  • A. save() comes after validation, and calling it does not prepare cleaned_data.
  • B. clean_all() is not a Django form method; cleaning is done in clean() and clean_fieldname().
  • D. render() produces HTML for display; it does not validate data or fill cleaned_data.

Tip: Always call is_valid() before accessing form.cleaned_data in Django.

Question 5Medium

What does a BoundField mean in a template as {{ form.name }}?

  1. A field rendered with its current data bound to the form
  2. The model's raw stored value, shown as plain text with no widget around it
  3. A database column
  4. A static label

Answer: A. A field rendered with its current data bound to the form

Explanation

Also {{ form.name.errors }} shows errors.

Step-by-step solution

  1. Access field.
  2. Render widget.

Why the other options are wrong

  • B. It renders a widget.
  • C. A BoundField is a form field bound to data, not a database column.
  • D. Label is separate.

Question 6Medium

What is the main difference between Form and ModelForm?

  1. Form supports validation, but ModelForm does not
  2. ModelForm works only inside the admin site
  3. Form cannot render itself as HTML at all
  4. ModelForm builds fields from a model and can save

Answer: D. ModelForm builds fields from a model and can save

Explanation

ModelForm links to a model with Meta.model and fields.

Step-by-step solution

  1. Form requires manual field definition and HTML rendering.
  2. ModelForm automatically creates fields from a model's attributes.
  3. ModelForm can save data directly to the database with save().
  4. Form needs extra code to handle saving data to the database.
  5. ModelForm simplifies form creation and data persistence.
  6. Final answer: ModelForm builds fields from a model and can save.

Why the other options are wrong

  • A. Form does not lack validation; both validate, but ModelForm adds model-based fields and saving.
  • B. ModelForm is not limited to the admin site; it works in any view.
  • C. A Form can render itself as HTML, for example with as_p or as_table.

Tip: Use ModelForm when linking to a database model; use Form for custom logic.

Question 7Medium

Where do you add validation for a single field email in a Form class?

  1. validate_email_field(self)
  2. check_email()
  3. clean_email(self)
  4. email_clean_hook()

Answer: C. clean_email(self)

Explanation

Per-field hooks are named clean_<field>; clean() validates across fields.

Step-by-step solution

  1. Name clean_email.
  2. Return the value.

Why the other options are wrong

  • A. validate_email_field(self) is not the Django hook name; the correct choice is clean_email(self).
  • B. check_email() is not the Django hook name; the correct choice is clean_email(self).
  • D. email_clean_hook() is not the Django hook name; the correct choice is clean_email(self).

Question 8Hard

What is the naming convention for a custom per-field validation method on a form?

  1. validate_<fieldname>()
  2. clean_<fieldname>()
  3. check_<fieldname>()
  4. <fieldname>_clean()

Answer: B. clean_<fieldname>()

Explanation

Django calls clean_<field> after the field's own clean.

Step-by-step solution

  1. A form's per-field check is a method named after the field.
  2. Django calls clean_<fieldname>() after the field's own clean.
  3. So the naming pattern is clean_<fieldname>: option B.

Why the other options are wrong

  • A. Validate_<fieldname>() is not the Django form hook name.
  • C. Check_<fieldname>() is not the Django form hook name.
  • D. The prefix clean_ comes first, not as a suffix.

Tip: Clean_<field> checks one field; clean() checks values across several fields.

Question 9Hard

What does form.save(commit=False) return for a ModelForm?

  1. A saved instance that already has a primary key assigned by the database
  2. A dict
  3. None
  4. An unsaved model instance you can modify before calling save()

Answer: D. An unsaved model instance you can modify before calling save()

Explanation

Handy for setting fields such as the owner from request.user.

Step-by-step solution

  1. commit False.
  2. Set field.
  3. Save.

Why the other options are wrong

  • A. It is not saved.
  • B. commit=False returns a model instance, not a dict of its values.
  • C. It returns an instance.

Practise all 9 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all Django topics · All topics