zerosleeps

Since 2010

Django form rendering

Thursday 19 May 2022

From the Django 4.1 release notes:

In order to aid users with screen readers, and other assistive technology, new <div> based form templates are available from this release. These provide more accessible navigation than the older templates, and are able to correctly group related controls, such as radio-lists, into fieldsets.

The new templates are recommended, and will become the default form rendering style when outputting a form, like {{ form }} in a template, from Django 5.0.

This is excellent news. Django form rendering has annoyed me for years because of the (subjectively) old-fashioned HTML tags and structures it uses by default. It’s always been close to “just working”, but simultaneously useless because the output is cumbersome to tweak, meaning I end up using my own templates anyway.

Fingers crossed these changes make it easier to stick to the defaults.