What Is New in Django 1.8
Django 1.8 is a significant release, notable for being a Long Term Support (LTS) version. It introduces a revamped template engine backend API, formalizes the support for multiple template engines, and brings in a slew of new features and improvements.
| Category | Key Highlights |
|---|---|
| New Features | Native PostgreSQL-specific fields, Formalized Multiple Template Engine support, New Template Backend API |
| Improvements | Enhanced Model._meta API, Security middleware updates, New database functions |
| Backwards Incompatibilities | Changes to session serialization, Default email backend switch, QuerySet.earliest() and .latest() behavior |
| Deprecated Features | django.contrib.webdesign, django.template.loader.BaseLoader, Several QuerySet methods |
How did templates get better in 1.8?
The template system received its most significant upgrade in years. The headline feature is the official support for multiple template engines configured through a new TEMPLATES setting, completely replacing the old TEMPLATE_* settings.
This change was powered by a new, well-defined template.backends.base.BaseEngine API. In practice, this means you can now seamlessly integrate engines like Jinja2 alongside Django's own templating language within a single project. The old django.template.loader.BaseLoader was deprecated as part of this modernization effort.
What new database features were added?
Database capabilities saw major expansions, especially for PostgreSQL users. The new django.contrib.postgres module introduced several powerful, database-specific field types that were previously only possible through extensions.
New PostgreSQL Fields
- ArrayField: For storing lists of data.
- HStoreField: A key-value field for semi-structured data.
- Range Fields: Including IntegerRangeField and BigIntegerRangeField.
This matters because it allows developers to leverage PostgreSQL's advanced data structures directly from their Django models, reducing the need for complex workarounds.
How was the Model _meta API improved?
The internal Model._meta API was formalized and stabilized. Previously considered a private API, it was officially documented and a set of public methods were introduced to access model metadata, replacing older, less reliable methods.
For example, instead of using model._meta.get_all_field_names(), which was deprecated, you should now use the official model._meta.get_fields(). This cleanup makes introspecting models for programmatic use, like writing generic admin tools, much more robust and future-proof.
What security enhancements were made?
The security middlewares were updated to provide more secure defaults. The most visible change was the switch to using django.core.mail.backends.smtp.EmailBackend as the new default email backend, moving away from the older console-based backend.
Additionally, the session serialization format was changed. The default format was switched from JSON to a more secure and robust format. This prevents potential issues when storing complex Python objects in sessions, a common source of deserialization headaches and vulnerabilities in the past.
FAQ
Is Django 1.8 an LTS release?
Yes, Django 1.8 is a Long Term Support (LTS) release. This means it received security updates and data loss fixes for an extended period, making it a stable foundation for long-running projects at the time.
What is the new setting for configuring templates?
You now use the TEMPLATES setting, which is a list of dictionaries configuring each template engine. This replaced the old TEMPLATE_LOADERS, TEMPLATE_DIRS, and other TEMPLATE_* settings.
How do I use the new PostgreSQL fields?
First, add 'django.contrib.postgres' to your INSTALLED_APPS. Then, you can import and use fields like ArrayField or HStoreField from django.contrib.postgres.fields in your models.
Why did my session data break after upgrading?
This is likely due to the change in the default session serialization format. To restore the old behavior temporarily, you can set SESSION_SERIALIZER to 'django.contrib.sessions.serializers.PickleSerializer', but it's recommended to migrate your session data to work with the new, more secure default.
What happened to django.contrib.webdesign?
The django.contrib.webdesign app, which contained the lorem template tag for generating placeholder text, was deprecated in Django 1.8. Its functionality was moved to the django.contrib.humanize app.