How can I disable ExtDeprecationWarning for external libs in flask

后端 未结 2 1152
故里飘歌
故里飘歌 2021-01-17 20:04

When I run my script, I get this output:

/app/venv/lib/python2.7/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.sqlalchemy is          


        
2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-17 20:13

    As of Flask 1.0, flask.ext does not exist. Packages that haven't fixed these imports will not work.


    First, you should care about this because the packages you're using aren't up to date. Report a bug that they should switch to using direct import names, such as flask_sqlalchemy, rather than the flask.ext import hook.

    Add a warnings.simplefilter line to filter out these warnings. You can place it wherever you're configuring your application, before performing any imports that would raise the warning.

    import warnings
    from flask.exthook import ExtDeprecationWarning
    
    warnings.simplefilter('ignore', ExtDeprecationWarning)
    

提交回复
热议问题