如何抑制 Django 中的弃用警告? [英] How to suppress the deprecation warnings in Django?

查看:27
本文介绍了如何抑制 Django 中的弃用警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我使用 django-admin 命令时——甚至在 TAB 完成时——它都会抛出一个 RemovedInDjango19Warning (如果我使用 test 命令).如何抑制这些警告?

Every time I'm using the django-admin command — even on TAB–completion — it throws a RemovedInDjango19Warning (and a lot more if I use the test command). How can I suppress those warnings?

我正在使用 Django 1.8 和 Python 3.4(在虚拟环境中).据我所知,所有这些警告都来自库而不是我的代码.

I'm using Django 1.8 with Python 3.4 (in a virtual environment). As far as I can tell, all those warnings come from libraries not from my code.

这里有一些例子:

  • …/lib/python3.4/importlib/_bootstrap.py:321: RemovedInDjango19Warning: django.contrib.contenttypes.generic 已弃用,将在 Django 1.9 中删除.它的内容已移至 django.contrib.contenttypes 的字段、表单和管理子模块.返回 f(*args, **kwds)

…/lib/python3.4/site-packages/django/contrib/admin/util.py:7: RemovedInDjango19Warning: django.contrib.admin.util 模块已重命名.请改用 django.contrib.admin.utils."改用 django.contrib.admin.utils.", RemovedInDjango19Warning)

…/lib/python3.4/site-packages/django/templatetags/future.py:25: RemovedInDjango19Warning: 从``future`` 库加载``url`` 标签是已弃用并将在 Django 1.9 中删除.请改用默认的 ``url`` 标签.RemovedInDjango19Warning)

自 Django 1.11 版(发行说明) 默认情况下,弃用警告不再响亮.所以我想这不再是问题了,因为 1.11 是支持 Python 2 的最后一个版本,并且还提供长期支持.

Since Django version 1.11 (release notes) deprecating warnings are no longer loud by default. So I guess this won't be an issue anymore, since 1.11 is the last version to support Python 2 and also features long-term support.

推荐答案

这个留给新人吧:

至于 django 1.11 弃用警告默认不再响亮.例如,要激活它们,请运行 python -Wd manage.py runserver.

As for django 1.11 deprecating warnings are no longer loud by default. To activate them run python -Wd manage.py runserver for example.

来源

这篇关于如何抑制 Django 中的弃用警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆