Files
flask-debugtoolbar/test/basic_app.py
Jeff Widman 70abd78e55 Setup DB properly
When I switched over to `flask run` entrypoint in b92391d177,
I forgot that the `if name==__main__` code no longer triggers.
So the SQLite in-memory database wasn't getting created for the example
app.

This moves the DB creation to a werkzeug/Flask hook that runs before the
first request to the app, so that the DB table is created when we query
it.

Also updated the test which worked fine previously, but this is more
idiomatic.
2020-03-09 10:01:59 -07:00

35 lines
771 B
Python

from flask import Flask, render_template
from flask_sqlalchemy import SQLAlchemy
from flask_debugtoolbar import DebugToolbarExtension
app = Flask('basic_app')
app.config['SECRET_KEY'] = 'abc123'
# TODO: This can be removed once flask_sqlalchemy 3.0 ships
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
# make sure these are printable in the config panel
app.config['BYTES_VALUE'] = b'\x00'
app.config['UNICODE_VALUE'] = u'\uffff'
toolbar = DebugToolbarExtension(app)
db = SQLAlchemy(app)
class Foo(db.Model):
__tablename__ = 'foo'
id = db.Column(db.Integer, primary_key=True)
@app.before_first_request
def setup():
db.create_all()
@app.route('/')
def index():
Foo.query.filter_by(id=1).all()
return render_template('basic_app.html')