Django 5.0 simplifies templates for form field rendering

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 AdminSite.get_model_admin() method returns an admin class for the given model class.
  • Properties in ModelAdmin.list_display 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 escape to each element of a sequence.

Copyright © 2023 IDG Communications, Inc.


This website uses cookies. By continuing to use this site, you accept our use of cookies.