Closed ev-agelos closed 9 years ago
I'm sorry, this should be on the documentation.
In order to see the queries on the Flask debug toolbar, you must activate first the query recording using the argument record_queries
:
db = SQLAlchemy(SQLALCHEMY_URI, app=app, record_queries=True)
(In Flask-SQLAlchemy
this is done automatically if DEBUG is True... I'll probably do something similar soon)
Here is a functional (but boring) example:
"""
pip install flask, sqlalchemy_wrapper, flask_debugtoolbar
"""
from flask import Flask
from sqlalchemy_wrapper import SQLAlchemy
app = Flask(__name__)
app.config['DEBUG'] = True
app.config['SECRET_KEY'] = 'loremipsumsitamet'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db'
app.config['DEBUG_TB_INTERCEPT_REDIRECTS'] = False
db = SQLAlchemy(
app.config['SQLALCHEMY_DATABASE_URI'],
record_queries=app.config['DEBUG'],
app=app
)
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.Unicode)
@app.route("/")
def hello():
db.query(User).all()
return "<html><body>Hello World!</body></html>"
db.create_all()
db.add(User(name=u'Test'))
db.commit()
if __name__ == "__main__":
if app.config['DEBUG']:
import flask_debugtoolbar
flask_debugtoolbar.DebugToolbarExtension(app)
app.run()
BTW, although SQLAlchemy-Wrapper is kind-of framework-independent this integration only works with Flask and Flask-DebugToolbar :(
As i am trying to make the "transition" from Flask-SQLAlchemy to your fork i found this problem where the debug toolbar doesnt show information about the queries, it just tells me that i have to install Flask-SQLAlachemy.
I saw a commit about supporting the toolbar in your fork but im not expert to debug what is wrong cause maybe im missing something.