Flask SQLAlchemy display queries for debug

后端 未结 8 1220
感情败类
感情败类 2021-02-03 17:21

I am developing an app with flask and SQL Alchemy. I need to display the queries executed to generate a page alongside the time each query took for debugging

What\'s the

8条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-03 18:04

    The other answer only works with flask_sqlalchemy, not flask and sqlalchemy.

    If you want to use native SQLAlchemy, you can do this as a quick fix: http://yuji.wordpress.com/2014/01/07/use-native-sqlalchemy-in-flask-debugtoolbar/

    from flask.ext.sqlalchemy import _EngineDebuggingSignalEvents
    _EngineDebuggingSignalEvents(engine, app.import_name).register()
    # use at your own risk! a development environment shouldn't really care though!
    

    The explain/select endpoints don't work without wiring them into your project manually, but at the very least your query debugger (count and sql) works. I was trying to understand what kind of queries my alchemy was forming, and I got it.

提交回复
热议问题