如何抑制Django中的弃用警告? [英] How to suppress the deprecation warnings in Django?
问题描述
每次我使用 django-admin
命令 - 即使在TAB完成 - 它会抛出一个 RemovedInDjango19Warning
(如果我使用测试命令,还有更多)。我如何禁止这些警告?
我在Python 3.4(在虚拟环境中)使用Django 1.8。
据我所知,所有这些警告来自图书馆,而不是我的代码,这里有一些例子:
-
... / lib / python3.4 / importlib / _bootstrap.py:321:RemovedInDjango19警告:django.contrib.contenttypes.generic已被弃用,将在Django 1.9中删除。其内容已被移动到django.contrib.contenttypes的字段,表单和管理子模块。
return f(* args,** kwds) -
... / lib / python3 .4 / site-packages / django / contrib / admin / util.py:7:RemovedInDjango19警告:django.contrib.admin.util模块已被重命名。改用django.contrib.admin.utils。
改用django.contrib.admin.utils,RemovedInDjango19Warning) -
... / lib / python3.4 / site-packages / django / templatetags / future.py:25:RemovedInDjango19警告:从``future``库加载``url``标签已被弃用,将在Django 1.9中删除。改用默认的``url``标签。
RemovedInDjango19Warning)
在查看我Django 1.8项目的其他依赖关系中的弃用警告时,使用
python -Wd manage.py runserver
,我可以通过暂时添加
过滤掉Django的弃用警告pre>
导入警告
从django.utils.deprecation import RemovedInDjango110警告
warnings.filterwarnings(action =ignore,category = RemovedInDjango110Warning)
到我的 settings.py
(可能在任何加载的模块中启动)。我不知道如何将过滤器作为一个额外的 -W
选项,即
python -Wd -Wi :: RemovedInDjango110警告manage.py runserver
导致忽略无效的-W选项:未知警告类别:RemovedInDjango110警告
。
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?
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, here are some examples:
…/lib/python3.4/importlib/_bootstrap.py:321: RemovedInDjango19Warning: django.contrib.contenttypes.generic is deprecated and will be removed in Django 1.9. Its contents have been moved to the fields, forms, and admin submodules of django.contrib.contenttypes. return f(*args, **kwds)
…/lib/python3.4/site-packages/django/contrib/admin/util.py:7: RemovedInDjango19Warning: The django.contrib.admin.util module has been renamed. Use django.contrib.admin.utils instead. "Use django.contrib.admin.utils instead.", RemovedInDjango19Warning)
…/lib/python3.4/site-packages/django/templatetags/future.py:25: RemovedInDjango19Warning: Loading the ``url`` tag from the ``future`` library is deprecated and will be removed in Django 1.9. Use the default ``url`` tag instead. RemovedInDjango19Warning)
While reviewing deprecation warnings in other dependencies of my Django 1.8 project, using
python -Wd manage.py runserver
, I was able to filter out Django deprecation warnings by temporarily adding
import warnings
from django.utils.deprecation import RemovedInDjango110Warning
warnings.filterwarnings(action="ignore", category=RemovedInDjango110Warning)
to my settings.py
(can presumably be in any module that's loaded at startup). I couldn't figure out how to include the filter as an extra -W
option, i.e.
python -Wd -Wi::RemovedInDjango110Warning manage.py runserver
resulted in Invalid -W option ignored: unknown warning category: 'RemovedInDjango110Warning'
.
这篇关于如何抑制Django中的弃用警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!