Paul Krill
Editor at Large

Django 5.0 simplifies templates for form field rendering

news
Dec 5, 20232 mins

Field group templates in Django 5.0 make it easier and more concise to render form field elements such as labels, widgets, help text, and errors.

Python laptop coding
Credit: Billion Photos / Shutterstock

The newly released Django 5.0, the latest version of the popular Python web framework, features capabilities such as simplified templates for form field rendering and database-computed default values.

Announced December 4, Django 5.0 can be installed with the pip package installer: pip install Django==5.0.

Django 5.0 introduces the concept of a field group and field group templates, which simplify the rendering of related elements of a Django form field such as its widget, label, errors, and help text, according to release notes. The new release also now shows facet counts for applied filters in the admin changelist when toggled on via the UI. This behavior can be changed through the new ModelAdmin.show_facets attribute.

A new Field.db_default parameter in Django 5.0 allows developers to set database-computed default values. In addition, a GeneratedField class enables creation of database-generated columns. This field can be used on all supported database back ends to build a field that is computed from other fields.

Django 5.0 offers more options for declaring field choices. Field.choices for model fields and ChoiceField.choices for form fields allow for more flexibility when declaring their values. Previously, choices should be either a list of two-tuples or an enumeration types subclass, but the latter required accessing the .choices attribute to provide values in the expected form.

Django 5.0 supports Python 3.10, Python 3.11, and Python 3.12. Following the release of Django 5.0, Django’s developers suggest that third-party app authors drop support for all versions prior to Django 4.2.

Other new features and improvements in Django 5.0:

  • A new Adminsite.get_log_entries() method allows customizing the query set for the site’s listed log entries.
  • Admin filters django.contrib.admin.AllValuesFieldListFilter, ChoicesFieldListFilter, and RelatedFieldListFilter now handle multi-valued query parameters.
  • XRegExp is upgraded from version 3.2.0 to 5.1.1.
  • The new <a href="https://docs.djangoproject.com/en/5.0/ref/contrib/admin/#django.contrib.admin.AdminSite.get_model_admin" rel="nofollow">AdminSite.get_model_admin()</a> method returns an admin class for the given model class.
  • Properties in <a href="https://docs.djangoproject.com/en/5.0/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_display" rel="nofollow">ModelAdmin.list_display</a> now support boolean attributes.
  • jQuery is upgraded from version 3.6.4 to 3.7.1.
  • For error reporting, sensitive_variables() and sensitive_post_parameters() now can be used with asynchronous functions.
  • The escapeseq template filter applies <a href="https://docs.djangoproject.com/en/5.0/ref/templates/builtins/#std-templatefilter-escape" rel="nofollow">escape</a> to each element of a sequence.
Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorld’s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorld’s audience of software developers and other information technology professionals. Paul has won a “Best Technology News Coverage” award from IDG.

More from this author