| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from flask import Flask |
| 4 |
from flask import render_template |
| 5 |
from flask_sqlalchemy import SQLAlchemy |
| 6 |
|
| 7 |
from flask_debugtoolbar import DebugToolbarExtension |
| 8 |
|
| 9 |
app = Flask("basic_app") |
| 10 |
app.config["DEBUG"] = True |
| 11 |
app.config["SECRET_KEY"] = "abc123" |
| 12 |
app.config["SQLALCHEMY_RECORD_QUERIES"] = True |
| 13 |
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///:memory:" |
| 14 |
# This is no longer needed for Flask-SQLAlchemy 3.0+, |
| 15 |
# if you're using 2.X you'll want to define this: |
| 16 |
# app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False |
| 17 |
|
| 18 |
# make sure these are printable in the config panel |
| 19 |
app.config["BYTES_VALUE"] = b"\x00" |
| 20 |
app.config["UNICODE_VALUE"] = "\uffff" |
| 21 |
|
| 22 |
toolbar = DebugToolbarExtension(app) |
| 23 |
db = SQLAlchemy(app) |
| 24 |
|
| 25 |
|
| 26 |
class Foo(db.Model): # type: ignore[name-defined, misc] |
| 27 |
__tablename__ = "foo" |
| 28 |
id = db.Column(db.Integer, primary_key=True) |
| 29 |
|
| 30 |
|
| 31 |
@app.route("/") |
| 32 |
def index() -> str: |
| 33 |
Foo.query.filter_by(id=1).all() |
| 34 |
return render_template("basic_app.html") |
| 35 |
|
| 36 |
|
| 37 |
with app.app_context(): |
| 38 |
db.create_all() |