Rendering forms in templates
Django offers five main ways to easily and quickly render a form object onto a page. The first three are to render a form using a paragraph, table, or list structure. The other two include the traditional way of rendering a form, which is based on the template in the django.forms.templates.django.forms
library called default.html
, and then a way to render your own template. New to Django 4.0 is the template_name
option on all form classes. This option allows you to point to a template file where you can structure your own HTML formatting.
Follow these steps to render your form objects:
- Copy the
base_template_1.html
file that was created in Chapter 4, URLs, Views, and Templates, into your/becoming_a_django_entdev/chapter_5/templates/chapter_5/base/
folder. Copy all related partial template files that are added as{% include %}
statements into that file as well. - That
base_template_1.html
file will be repurposed as the base template for this...