diff --git a/example/app.py b/example/app.py index a466be6..23a9253 100644 --- a/example/app.py +++ b/example/app.py @@ -1,4 +1,6 @@ -# Run using: `FLASK_DEBUG=True flask run` +# Run using: `flask run` after setting env vars + +import os from flask import Flask from flask import redirect @@ -9,29 +11,28 @@ from flask_debugtoolbar import DebugToolbarExtension app = Flask(__name__) -app.config["DEBUG_TB_INTERCEPT_REDIRECTS"] = True -# app.config['DEBUG_TB_PANELS'] = ( -# 'flask_debugtoolbar.panels.headers.HeaderDebugPanel', -# 'flask_debugtoolbar.panels.logger.LoggingPanel', -# 'flask_debugtoolbar.panels.timer.TimerDebugPanel', -# ) -# app.config['DEBUG_TB_HOSTS'] = ('127.0.0.1', '::1' ) + +# Use a cross-platform-safe DB path +basedir = os.path.abspath(os.path.dirname(__file__)) +app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + os.path.join(basedir, "test.db") + app.config["SECRET_KEY"] = "asd" app.config["SQLALCHEMY_RECORD_QUERIES"] = True -app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:////tmp/test.db" -# This is no longer needed for Flask-SQLAlchemy 3.0+, if you're using 2.X you'll -# want to define this: -# app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False +app.config["DEBUG_TB_INTERCEPT_REDIRECTS"] = True +app.config["DEBUG"] = True # ✅ Ensure app runs in debug mode +app.debug = True # ✅ Double-safe flag for debug db = SQLAlchemy(app) toolbar = DebugToolbarExtension(app) +# Model class ExampleModel(db.Model): __tablename__ = "examples" value = db.Column(db.String(100), primary_key=True) +# Routes @app.route("/") def index(): app.logger.info("Hello there") @@ -46,5 +47,6 @@ def redirect_example(): return response +# Create the database with app.app_context(): db.create_all() diff --git a/example/test.db b/example/test.db new file mode 100644 index 0000000..0b40655 Binary files /dev/null and b/example/test.db differ diff --git a/src/flask_debugtoolbar/__init__.py b/src/flask_debugtoolbar/__init__.py index f223f3d..04ed72b 100644 --- a/src/flask_debugtoolbar/__init__.py +++ b/src/flask_debugtoolbar/__init__.py @@ -357,3 +357,11 @@ def teardown_request(self, exc: BaseException | None) -> None: def render(self, template_name: str, context: dict[str, t.Any]) -> str: template = self.jinja_env.get_template(template_name) return template.render(**context) + + +@module.route("/toggle_redirect_intercept", methods=["POST"]) +def toggle_redirect_intercept() -> Response: + current = current_app.config.get("DEBUG_TB_INTERCEPT_REDIRECTS", True) + new_value = not current + current_app.config["DEBUG_TB_INTERCEPT_REDIRECTS"] = new_value + return {"intercept_redirects": new_value} diff --git a/src/flask_debugtoolbar/templates/base.html b/src/flask_debugtoolbar/templates/base.html index 13e10f6..ddd90a0 100644 --- a/src/flask_debugtoolbar/templates/base.html +++ b/src/flask_debugtoolbar/templates/base.html @@ -10,6 +10,13 @@