| 1 |
# Run using: `FLASK_DEBUG=True flask run` |
| 2 |
|
| 3 |
from flask import Flask |
| 4 |
from flask import redirect |
| 5 |
from flask import render_template |
| 6 |
from flask import url_for |
| 7 |
from flask_sqlalchemy import SQLAlchemy |
| 8 |
|
| 9 |
from flask_debugtoolbar import DebugToolbarExtension |
| 10 |
|
| 11 |
app = Flask(__name__) |
| 12 |
app.config["DEBUG_TB_INTERCEPT_REDIRECTS"] = True |
| 13 |
# app.config['DEBUG_TB_PANELS'] = ( |
| 14 |
# 'flask_debugtoolbar.panels.headers.HeaderDebugPanel', |
| 15 |
# 'flask_debugtoolbar.panels.logger.LoggingPanel', |
| 16 |
# 'flask_debugtoolbar.panels.timer.TimerDebugPanel', |
| 17 |
# ) |
| 18 |
# app.config['DEBUG_TB_HOSTS'] = ('127.0.0.1', '::1' ) |
| 19 |
app.config["SECRET_KEY"] = "asd" |
| 20 |
app.config["SQLALCHEMY_RECORD_QUERIES"] = True |
| 21 |
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:////tmp/test.db" |
| 22 |
# This is no longer needed for Flask-SQLAlchemy 3.0+, if you're using 2.X you'll |
| 23 |
# want to define this: |
| 24 |
# app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False |
| 25 |
|
| 26 |
db = SQLAlchemy(app) |
| 27 |
toolbar = DebugToolbarExtension(app) |
| 28 |
|
| 29 |
|
| 30 |
class ExampleModel(db.Model): |
| 31 |
__tablename__ = "examples" |
| 32 |
value = db.Column(db.String(100), primary_key=True) |
| 33 |
|
| 34 |
|
| 35 |
@app.route("/") |
| 36 |
def index(): |
| 37 |
app.logger.info("Hello there") |
| 38 |
ExampleModel.query.get(1) |
| 39 |
return render_template("index.html") |
| 40 |
|
| 41 |
|
| 42 |
@app.route("/redirect") |
| 43 |
def redirect_example(): |
| 44 |
response = redirect(url_for("index")) |
| 45 |
response.set_cookie("test_cookie", "1") |
| 46 |
return response |
| 47 |
|
| 48 |
|
| 49 |
with app.app_context(): |
| 50 |
db.create_all() |