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
- Defining a forms.Form
- is_valid and cleaned_data
- Rendering Forms in Templates
- CSRF Protection and the POST Flow