Reputation: 2832
With the new django.apps
in Django 1.7, I'm now encountering a situation where the Django version will trigger the way an __init__
file handles configuration. For example:
from django.apps import AppConfig
...
Will not work on 1.6 and below. So it would be useful to check the version. My question: what's the canonical way for checking the version of Django?
String comparison? (this just seems funky)
if django.get_version() >= '1.7.0'
Or accessing the version tuple?
major_version == django.VERSION[0]
minor_version == django.VERSION[1]
if major_version >= 1 and minor_version >= 7
Obviously, the second method would fail on 2.0, and we could just say meh... I'll cross that bridge when I get there, but that certainly does not seem elegant.
Is there a third option? Thanks in advance!
Upvotes: 2
Views: 85
Reputation: 799082
Sequences in Python are compared naturally.
>>> (2, 0, 0) > (1, 7)
True
>>> (1, 6) > (1, 7)
False
>>> (1, 6, 2) > (1, 7)
False
Upvotes: 5