如何禁用 Flask 中外部库的 ExtDeprecationWarning

2023-11-22

当我运行脚本时,我得到以下输出:

/app/venv/lib/python2.7/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.sqlalchemy is deprecated, use flask_sqlalchemy instead.
  .format(x=modname), ExtDeprecationWarning
/app/venv/lib/python2.7/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.marshmallow is deprecated, use flask_marshmallow instead.
  .format(x=modname), ExtDeprecationWarning
/app/venv/lib/python2.7/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.cache is deprecated, use flask_cache instead.
  .format(x=modname), ExtDeprecationWarning
/app/venv/lib/python2.7/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.restful is deprecated, use flask_restful instead.
  .format(x=modname), ExtDeprecationWarning
/app/venv/lib/python2.7/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.restful.fields is deprecated, use flask_restful.fields instead.
  .format(x=modname), ExtDeprecationWarning
/app/venv/lib/python2.7/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.restful.reqparse is deprecated, use flask_restful.reqparse instead.
  .format(x=modname), ExtDeprecationWarning
/app/venv/lib/python2.7/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.restplus is deprecated, use flask_restplus instead.
  .format(x=modname), ExtDeprecationWarning
/app/venv/lib/python2.7/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.restful.representations is deprecated, use flask_restful.representations instead.
  .format(x=modname), ExtDeprecationWarning
/app/venv/lib/python2.7/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.script is deprecated, use flask_script instead.
  .format(x=modname), ExtDeprecationWarning
/app/venv/lib/python2.7/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.migrate is deprecated, use flask_migrate instead.
  .format(x=modname), ExtDeprecationWarning

我真的不在乎这个,因为外部库导致了这个。我无法更新这些库,因为我不拥有它们,而且我发现有几个库有待处理的拉取请求。

我怎样才能得到一些平静和安宁呢?


从 Flask 1.0 开始,flask.ext不存在。没有修复这些导入的软件包将无法工作。


首先你should关心这一点是因为您使用的软件包不是最新的。报告一个错误,他们应该切换到使用直接导入名称,例如flask_sqlalchemy,而不是flask.ext导入钩子。

Add a warnings.simplefilter行来过滤掉这些警告。在执行任何会引发警告的导入之前,您可以将其放置在配置应用程序的任何位置。

import warnings
from flask.exthook import ExtDeprecationWarning

warnings.simplefilter('ignore', ExtDeprecationWarning)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何禁用 Flask 中外部库的 ExtDeprecationWarning 的相关文章

随机推荐