How to check Django version

后端 未结 26 2685
梦如初夏
梦如初夏 2020-12-04 04:36

I have to use Python and Django for our application. So I have two versions of Python, 2.6 and 2.7. Now I have installed Django. I could run the sample application for testi

26条回答
  •  孤街浪徒
    2020-12-04 05:17

    For Python:

    import sys
    sys.version
    

    For Django (as mentioned by others here):

    import django
    django.get_version()
    

    The potential problem with simply checking the version, is that versions get upgraded and so the code can go out of date. You want to make sure that '1.7' < '1.7.1' < '1.7.5' < '1.7.10'. A normal string comparison would fail in the last comparison:

    >>> '1.7.5' < '1.7.10'
    False
    

    The solution is to use StrictVersion from distutils.

    >>> from distutils.version import StrictVersion
    >>> StrictVersion('1.7.5') < StrictVersion('1.7.10')
    True
    

提交回复
热议问题