Get the version of Django for application

后端 未结 6 1660
感动是毒
感动是毒 2021-02-18 22:33

I am starting a new (actually very old) project which I know is in Django. I am getting lost knowing the exact version of Django it has been build upon. Is there a way I can kno

6条回答
  •  离开以前
    2021-02-18 23:19

    You can guess based on the way settings.py is laid out. Your first hint would be from database settings. The old way prior to Django 1.2 was:

    DATABASE_ENGINE = 'sqlite3'           # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
    DATABASE_NAME = os.path.join(BASE_DIR, 'db')             # Or path to database file if using sqlite3.
    #DATABASE_USER = ''             # Not used with sqlite3.
    #DATABASE_PASSWORD = ''         # Not used with sqlite3.
    #DATABASE_HOST = ''             # Set to empty string for localhost. Not used with sqlite3.
    #DATABASE_PORT = ''             # Set to empty string for default. Not used with sqlite3.
    

    This method is still supported up to 1.3 but now causes Django to complain loudly about it being deprecated.

    As of Django 1.2 the following format is used:

    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': os.path.join(PROJECT_DIR, 'mycms.db'),
        }
    }
    

    While this isn't definitive, it does at least give you a hint to whether your app was written either before or after Django 1.2.

    Keep in mind is that an app written against an older version of Django should still work, but you'll likely get a lot of deprecation warnings on the console if your code is referencing stuff that has been deprecated or just moved around.

    These warnings can usually safely be ignored in the short-term but you should definitely take time to silence them by updating your code to reference the features in their new home/format. The Django devs do a good job of doing the right thing as far as giving ample time and warning for older functionality to be properly migrated as time goes by.

提交回复
热议问题