0Pricing
Django Academy · Lesson

Rendering Forms in Templates

Output fields, labels, and errors safely.

Pass the Form In

Send your form to the template through the context, just like any other variable, so it can be rendered.

return render(request, "contact.html",
    {"form": form})

Render Everything at Once

Printing {{ form }} outputs every field with its label, widget, and errors. It is the fastest way to get a working form.

<form method="post">
  {{ form }}
</form>

All lessons in this course

  1. Defining a forms.Form
  2. is_valid and cleaned_data
  3. Rendering Forms in Templates
  4. CSRF Protection and the POST Flow
← Back to Django Academy