What Is New in Django 2.0
Django 2.0 introduces significant updates focused on simplifying URL routing, expanding database support, and modernizing the framework's core. This release streamlines common development patterns and drops support for older Python versions to encourage a more modern stack.
| Category | Key Changes |
|---|---|
| New Features | Simplified URL routing syntax, PostgreSQL-specific indexes, Mobile-friendly admin |
| Backwards Incompatibilities | Dropped support for Python 2.7, Changed on_delete behavior for ForeignKeys |
| Database Support | Dropped support for PostgreSQL 9.3 and Oracle 11.2, Added BRIN and GIST indexes |
| Deprecated Features | django.core.urlresolvers module moved, context argument removed from Field._formfield() |
How does the new URL routing syntax work?
The old url() function is superseded by a simpler path-based syntax. You now use path() for basic routes and re_path() for complex regex patterns, making URLconfs more readable.
Instead of confusing regex groups, you define converters like <int:year> directly in the path string. This approach reduces boilerplate and makes parameter extraction straightforward.
# Old syntax
url(r'^articles/(?P<year>[0-9]{4})/$', views.year_archive)
# New syntax
path('articles/<int:year>/', views.year_archive)
What database changes should I prepare for?
Django 2.0 requires PostgreSQL 9.4+ and Oracle 12.1+, dropping older versions. If you're still running PostgreSQL 9.3 or Oracle 11.2, you'll need to upgrade your database before migrating to Django 2.0.
The framework adds powerful PostgreSQL-specific indexes through the django.contrib.postgres module. You can now create BRIN, GIST, and GIN indexes directly from your models for better query optimization.
Why is on_delete now required for ForeignKeys?
Previously, on_delete was optional with a default that encouraged poor practices. Django 2.0 makes it mandatory to force explicit behavior definition for relational integrity.
This change prevents accidental data loss by requiring developers to consciously choose what happens when referenced objects are deleted. You must now specify on_delete=models.CASCADE, PROTECT, SET_NULL, or other behaviors for every ForeignKey.
What Python versions are supported?
Django 2.0 supports Python 3.4, 3.5, and 3.6 exclusively. Python 2.7 support has been completely removed, reflecting the Django project's commitment to the Python 3 ecosystem.
This aligns with Python's own end-of-life schedule for version 2.7. In practice, this means you'll need to ensure all your dependencies are Python 3 compatible before upgrading.
How has the admin interface improved?
The admin now uses responsive CSS, making it functional on mobile devices. This is a significant quality-of-life improvement for developers and content managers who need to make quick changes on the go.
Additionally, the admin site now supports a main_menu and user_menu properties for easier customization of the navigation structure without overriding templates.
FAQ
Can I upgrade from Django 1.11 directly to 2.0?
Yes, but you'll need to address several backwards incompatible changes first. Most importantly, ensure all your ForeignKey and OneToOneField definitions include an explicit on_delete argument and that your codebase runs on Python 3.4+.
What happens if I don't specify on_delete for ForeignKeys?
Your code will raise a TypeError during model definition. Django 2.0 requires this parameter for every ForeignKey and OneToOneField, unlike previous versions where it was optional with a default value.
Does the new URL syntax replace all my existing url() patterns?
No, you can still use re_path() which is equivalent to the old url() function. The new path() syntax is optional but recommended for simpler, more readable routes.
Why was support for older databases dropped?
PostgreSQL 9.3 and Oracle 11.2 reached their end-of-life, and maintaining support limited Django's ability to implement modern database features. This allows the framework to leverage newer database capabilities.
Are third-party packages compatible with Django 2.0?
Many popular packages were updated quickly, but you should check each package's documentation. Packages that haven't been maintained might have compatibility issues, especially with the Python 3 requirement and mandatory on_delete parameter.