Django 5.0, the latest version of the popular web framework, was officially released on December 4, 2023.

This significant update brings a host of new features, improvements, and optimizations, making it a substantial leap forward from its predecessor, Django 4.2.

The release is tailored to enhance the efficiency and capability of web development, offering developers more tools and functionalities to build robust web applications.

The key highlights of Django 5.0 include:

  • Enhanced Python compatibility, now supporting Python versions 3.10, 3.11, and 3.12.
  • Introduction of new features such as Facet Filters in the Admin, Simplified Templates for Form Field Rendering, and Database-Computed Default Values.
  • Implementation of Database Generated Model Fields, adding more flexibility and efficiency to database interactions.
  • Expanded options for declaring field choices, allowing for more versatile and dynamic form and model field configurations.
  • Numerous minor feature additions and improvements across various Django modules, including django.contrib.admin, django.contrib.auth, and more.
  • Backwards incompatible changes and deprecations that aim to streamline the framework and set the stage for future developments.

This release marks a significant milestone in Django's evolution, offering enhanced functionality and greater ease of use for developers around the globe.


Python Compatibility

Django 5.0 introduces compatibility with newer versions of Python, significantly broadening its reach and capabilities.

This version of Django supports Python 3.10, 3.11, and 3.12.

This expansion in compatibility ensures that Django stays in sync with the latest advancements in Python, offering developers the benefits of the newest features and improvements in the Python ecosystem.

While Django 5.0 supports these three versions of Python, the Django team highly recommends using the latest release of each series.

This recommendation is made to ensure the best possible performance, security, and access to the latest features.

Using the most recent Python release guarantees that developers can leverage the full potential of Django 5.0, benefiting from the optimized compatibility and enhancements that come with the latest Python versions.


New Features in Django 5.0

Facet Filters in the Admin

Django 5.0 introduces facet counts for applied filters in the admin changelist.

This feature, which can be toggled via the UI, enhances the admin interface by displaying facet counts alongside filters, providing a quick overview of the data distribution.

The behavior of facet filters can be configured using the ModelAdmin.show_facets attribute..

Simplified Templates for Form Field Rendering

This release simplifies the rendering of Django form fields with the introduction of field group templates.

These templates facilitate the streamlined rendering of form field components such as labels, widgets, help text, and errors, enhancing both the efficiency and clarity of form presentation.

Before:

<form>
...
<div>
  {{ form.name.label_tag }}
  {% if form.name.help_text %}
    <div class="helptext" id="{{ form.name.auto_id }}_helptext">
      {{ form.name.help_text|safe }}
    </div>
  {% endif %}
  {{ form.name.errors }}
  {{ form.name }}
  <div class="row">
    <div class="col">
      {{ form.email.label_tag }}
      {% if form.email.help_text %}
        <div class="helptext" id="{{ form.email.auto_id }}_helptext">
          {{ form.email.help_text|safe }}
        </div>
      {% endif %}
      {{ form.email.errors }}
      {{ form.email }}
    </div>
    <div class="col">
      {{ form.password.label_tag }}
      {% if form.password.help_text %}
        <div class="helptext" id="{{ form.password.auto_id }}_helptext">
          {{ form.password.help_text|safe }}
        </div>
      {% endif %}
      {{ form.password.errors }}
      {{ form.password }}
    </div>
  </div>
</div>
...
</form>

Now becomes:

<form>
...
<div>
  {{ form.name.as_field_group }}
  <div class="row">
    <div class="col">{{ form.email.as_field_group }}</div>
    <div class="col">{{ form.password.as_field_group }}</div>
  </div>
</div>
...
</form>

Tagged in: