获取应用程序的Django版本

发布于 2024-11-17 23:19:21 字数 99 浏览 1 评论 0原文

我正在开始一个新的(实际上非​​常旧的)项目,我知道它是在 Django 中的。我不知道它所构建的 Django 的确切版本。有没有办法知道我的应用程序正在运行的 Django 版本?

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 know the version of Django my application is running?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

幸福丶如此 2024-11-24 23:19:21

唯一的方法就是猜测。我首先查看 settings.py 文件(或其他基础项目文件)的创建日期

版本的发布日期:

  • 1.0:2008 年 9 月。(?)
  • 1.1:2009 年 7 月 29 日 [1]
  • 1.2:2010 年 5 月 17 日 [2]
  • 1.3:2011 年 3 月 23 日 [3]

在你的 urls.py 中有:[4]

from django.conf.urls.defaults import *
from django.contrib import admin

或应用程序中有一个 admin.py 文件[5]表明这是一个1.0+项目。

在你的 urls.py 中: [6< /a>]

(r'^admin/', include(admin.site.urls)),

建议 1.1+。

在你的settings.py文件中:

DATABASES = {
    'default': {
        'NAME': 'app_data',
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'USER': 'postgres_user',
        'PASSWORD': 's3krit'
    },
    'users': {
        'NAME': 'user_data',
        'ENGINE': 'django.db.backends.mysql',
        'USER': 'mysql_user',
        'PASSWORD': 'priv4te'
    }
}

建议1.2+。

[1]: 1.1 发行说明

[2]: 1.2 发行说明

[3]:1.3 发行说明

[4]:向后不兼容更改 0.96 > 1.0

[5]: 向后不兼容更改 0.96 > 1.0

[6]:多个数据库

The only way is to take a guess. I would start by looking at the created date of the settings.py file (or other base project files)

Release dates for versions:

  • 1.0: September 2008. (?)
  • 1.1: July 29, 2009 [1]
  • 1.2: May 17, 2010 [2]
  • 1.3: March 23, 2011 [3]

Having in your urls.py:[4]

from django.conf.urls.defaults import *
from django.contrib import admin

or having an admin.py file in an application [5] suggests that it is a 1.0+ project.

Having in your urls.py: [6]

(r'^admin/', include(admin.site.urls)),

would suggest 1.1+.

Having in your settings.py file:

DATABASES = {
    'default': {
        'NAME': 'app_data',
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'USER': 'postgres_user',
        'PASSWORD': 's3krit'
    },
    'users': {
        'NAME': 'user_data',
        'ENGINE': 'django.db.backends.mysql',
        'USER': 'mysql_user',
        'PASSWORD': 'priv4te'
    }
}

would suggest 1.2+.

[1]: 1.1 release notes

[2]: 1.2 release notes

[3]: 1.3 release notes

[4]: Backwards Incompatible changes 0.96 > 1.0

[5]: Backwards Incompatible changes 0.96 > 1.0

[6]: Multiple databases

迷路的信 2024-11-24 23:19:21

您可以根据 settings.py 的布局方式进行猜测。您的第一个提示将来自数据库设置。 Django 1.2 之前的旧方法是:

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.

此方法在 1.3 之前仍然受支持,但现在导致 Django 大声抱怨它已被弃用。

从 Django 1.2 开始,使用以下格式:

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

虽然这不是确定的,但它至少可以提示您应用程序是在 Django 1.2 之前还是之后编写的。

请记住,针对旧版本 Django 编写的应用程序应该仍然可以工作,但如果您的代码引用了已弃用或刚刚移动的内容,您可能会在控制台上收到大量弃用警告。

通常可以在短期内安全地忽略这些警告,但您绝对应该花时间通过更新代码以引用其新主页/格式中的功能来消除它们。 Django 开发人员在做正确的事情方面做得很好,他们提供了充足的时间,并警告旧功能随着时间的推移可以正确迁移。

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.

海的爱人是光 2024-11-24 23:19:21

我看到上面接受的答案,我认为这要容易得多。也许我错过了一些东西,但这就是我要做的。

打开路径上有 Django 项目的 python 终端。

$ python
>>> import django
>>> print django.get_version()
0.97-pre-SVN-7668

该版本号仅供参考。我希望你的可能会有所不同。

I see the answer accepted above and I think it's much easier. Maybe I'm missing something, but this is what I would do.

Open a python terminal that has the Django project on its path.

$ python
>>> import django
>>> print django.get_version()
0.97-pre-SVN-7668

That version number is strictly for illustration. Yours may differ, I hope.

阪姬 2024-11-24 23:19:21

这适用于 Django 1.7:

import django
django.VERSION

...产生(在我的机器上) :

(1, 7, 0, 'rc', 3)

注意:在运行此命令之前,您需要确保在 python 虚拟环境中运行,这一点很重要,否则您将导入系统范围的 django,而不是在项目级别。

This works in Django 1.7:

import django
django.VERSION

...which yields (on my machine):

(1, 7, 0, 'rc', 3)

Note: It's important that you need to make sure you are running inside a python virtual environment before running this, as otherwise you'd importing the system wide django, not at the project level.

皇甫轩 2024-11-24 23:19:21

https://docs.djangoproject.com/en/1.7/intro/tutorial01/:

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

这让我得到以下结果:

1.7.1

https://docs.djangoproject.com/en/1.7/intro/tutorial01/:

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

which gets me the following:

1.7.1
丑丑阿 2024-11-24 23:19:21
Django settings for ********** project.

Generated by 'django-admin startproject' using Django 2.0.9.

For more information on this file, see
https://docs.djangoproject.com/en/2.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.0/ref/settings/

当您打开 settings.py 文件时,您可以看到上面的 django 版本。

Django settings for ********** project.

Generated by 'django-admin startproject' using Django 2.0.9.

For more information on this file, see
https://docs.djangoproject.com/en/2.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.0/ref/settings/

when you open your settings.py file you can see the django version above.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文