How to check Django version

后端 未结 26 2557
梦如初夏
梦如初夏 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:20

    As you say you have two versions of Python, I assume they are in different virtual environments (e.g. venv) or perhaps Conda environments.

    When you installed Django, it was likely in only one environment. It is possible that you have two different versions of Django, one for each version of python.

    In from a Unix/Mac terminal, you can check your Python version as follows:

    $ python --version
    

    If you want to know the source:

    $ which python
    

    And to check the version of Django:

    $ python -m django --version
    
    0 讨论(0)
  • 2020-12-04 05:20

    For checking using a Python shell, do the following.

    >>>from django import get_version
    >>> get_version()
    

    If you wish to do it in Unix/Linux shell with a single line, then do

    python -c 'import django; print(django.get_version())'
    

    Once you have developed an application, then you can check version directly using the following.

    python manage.py runserver --version
    
    0 讨论(0)
  • 2020-12-04 05:21

    There are various ways to get the Django version. You can use any one of the following given below according to your requirements.

    Note: If you are working in a virtual environment then please load your python environment


    Terminal Commands

    1. python -m django --version
    2. django-admin --version or django-admin.py version
    3. ./manage.py --version or python manage.py --version
    4. pip freeze | grep Django
    5. python -c "import django; print(django.get_version())"
    6. python manage.py runserver --version

    Django Shell Commands

    1. import django django.get_version() OR django.VERSION
    2. from django.utils import version version.get_version() OR version.get_complete_version()
    3. import pkg_resources pkg_resources.get_distribution('django').version

    (Feel free to modify this answer, if you have some kind of correction or you want to add more related information.)

    0 讨论(0)
  • 2020-12-04 05:21

    You can do it without Python too. Just type this in your Django directory:

    cat __init__.py | grep VERSION
    

    And you will get something like:

    VERSION = (1, 5, 5, 'final', 0)
    
    0 讨论(0)
  • 2020-12-04 05:22

    Type in your CMD or terminal:

    python -m django --version
    
    0 讨论(0)
  • 2020-12-04 05:23

    You can get django version by running the following command in a shell prompt

    python -m django --version

    If Django is installed, you should see the version otherwise you’ll get an error telling “No module named django”.

    0 讨论(0)
提交回复
热议问题