Django 2.0 got released on 2 December 2017 and is packed with great new features that make our lives easier.
Trying Django 2.0 is super simple with SourceLair; all you need is a modern browser and an internet connection.
To get started:
- Visit https://lair.io/sourcelair/django-2
- Create your project by using the dialog
- Write some code!
What's new in Django 2.0?
Simplified URL routing syntax
The new django.urls.path()
function allows a simpler, more readable URL routing syntax.
For example, this routing from previous Django releases:
url(r'^articles/(?P<year>[0-9]{4})/$', views.year_archive),
can be written as:
path('articles/<int:year>/', views.year_archive),
Mobile friendly contrib.admin
The build-in admin dashboard of Django is now responsive and supports all major mobile devices.
This is super useful, when you need to update some of your models in your live app, but your are on the go.
Window expressions
The new Window
expression allows adding an OVER
clause to your querysets and also do "magic" like the following:
from django.db.models import Avg, F, Window
from django.db.models.functions import ExtractYear
Movie.objects.annotate(
avg_rating=Window(
expression=Avg('rating'),
partition_by=[F('studio'), F('genre')],
order_by=ExtractYear('released').asc(),
),
)
🙌 Django 2.0 is the first release to drop support for Python 2 (works exclusively on Python 3) and is the last release to support Python 3.4.
Want to learn more about Django 2.0 (minor features, deprecations, breaking changes)? Take a look at the release notes.