Recently I was dived in Django
,and I wondered that how the developer make a compatibility of the different Django
version ? Not talking about the detail of the change ,but just the name
of API of and the path
of the API.
Here is a example :
Before Django 1.10
in settings.py
Django provides django.utils.deprecation.MiddlewareMixin to ease creating middleware classes that are compatible with both
MIDDLEWARE
and the oldMIDDLEWARE_CLASSES
. All middleware classes included with Django are compatible with both settings.
What I try is :
import django
if django.get_version() > '1.11.0':
MIDDLEWARE= ('...','....')
else:
MIDDLEWARE_CLASSES = ('...','....')
Django's deprecation policy is designed so that you can support multiple versions of Django at once.
Even though MIDDLEWARE
was added in Django 1.10, you can still use MIDDLEWARE_CLASSES
in Django 1.0 and 1.11.
At first, you would use MIDDLEWARE_CLASSES
. This would allow you to support (for example), Django 1.8, 1.9, 1.10 and 1.11 LTS.
Then, when you want to support Django 2.0, you would switch to MIDDLEWARE
, and drop support for Django 1.10 and earlier, and support only Django 1.11 and Django 2.0.
If you try to keep support for multiple versions of Django e.g. Django 1.8, Django 1.11 and Django 2.0, then this may lead to more complicated code. Note that Django 1.11 LTS is the oldest supported version of Django. All earlier versions are now unsupported and do not receive security fixes.