Django: what’s new in 6.0

https://news.ycombinator.com/rss Hits: 20
Summary

Django: what’s new in 6.02025-12-03Django 6.0 was released today, starting another release cycle for the loved and long-lived Python web framework (now 20 years old!). It comes with a mosaic of new features, contributed to by many, some of which I am happy to have helped with. Below is my pick of highlights from the release notes.Upgrade with help from django-upgradeIf you’re upgrading a project from Django 5.2 or earlier, please try my tool django-upgrade. It will automatically update old Django code to use new features, fixing some deprecation warnings for you, including five fixers for Django 6.0. (One day, I’ll propose django-upgrade to become an official Django project, when energy and time permit…)Template partialsThere are four headline features in Django 6.0, which we’ll cover before other notable changes, starting with this one:The Django Template Language now supports template partials, making it easier to encapsulate and reuse small named fragments within a template file.Partials are sections of a template marked by the new {% partialdef %} and {% endpartialdef %} tags. They can be reused within the same template or rendered in isolation. Let’s look at examples for each use case in turn.Reuse partials within the same templateThe below template reuses a partial called filter_controls within the same template. It’s defined once at the top of the template, then used twice later on. Using a partial allows the template avoid repetition without pushing the content into a separate include file.<section id=videos> {% partialdef filter_controls %} <form> {{ filter_form }} </form> {% endpartialdef %} {% partial filter_controls %} <ul> {% for video in videos %} <li> <h2>{{ video.title }}</h2> ... </li> {% endfor %} </ul> {% partial filter_controls %} </section> Actually, we can simplify this pattern further, by using the inline option on the partialdef tag, which causes the definition to also render in place:<section id=videos> {% partialdef filter_controls inline %...

First seen: 2025-12-09 21:30

Last seen: 2025-12-10 16:34