获取应用程序的Django版本
我正在开始一个新的(实际上非常旧的)项目,我知道它是在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
唯一的方法就是猜测。我首先查看 settings.py 文件(或其他基础项目文件)的创建日期
版本的发布日期:
在你的 urls.py 中有:[4]
或应用程序中有一个
admin.py
文件[5]表明这是一个1.0+项目。在你的 urls.py 中: [6< /a>]
建议 1.1+。
在你的settings.py文件中:
建议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:
Having in your urls.py:[4]
or having an
admin.py
file in an application [5] suggests that it is a 1.0+ project.Having in your urls.py: [6]
would suggest 1.1+.
Having in your settings.py file:
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
您可以根据 settings.py 的布局方式进行猜测。您的第一个提示将来自数据库设置。 Django 1.2 之前的旧方法是:
此方法在 1.3 之前仍然受支持,但现在导致 Django 大声抱怨它已被弃用。
从 Django 1.2 开始,使用以下格式:
虽然这不是确定的,但它至少可以提示您应用程序是在 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:
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:
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.
我看到上面接受的答案,我认为这要容易得多。也许我错过了一些东西,但这就是我要做的。
打开路径上有 Django 项目的 python 终端。
该版本号仅供参考。我希望你的可能会有所不同。
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.
That version number is strictly for illustration. Yours may differ, I hope.
这适用于 Django 1.7:
...产生(在我的机器上) :
注意:在运行此命令之前,您需要确保在 python 虚拟环境中运行,这一点很重要,否则您将导入系统范围的 django,而不是在项目级别。
This works in Django 1.7:
...which yields (on my machine):
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.
https://docs.djangoproject.com/en/1.7/intro/tutorial01/:
这让我得到以下结果:
https://docs.djangoproject.com/en/1.7/intro/tutorial01/:
which gets me the following:
当您打开
settings.py
文件时,您可以看到上面的 django 版本。when you open your
settings.py
file you can see the django version above.