mirror of
https://github.com/pallets-eco/flask-debugtoolbar.git
synced 2026-04-30 13:29:14 -05:00
Implement the ability to intercept redirects (like in the django debug toolbar)
This commit is contained in:
+11
-1
@@ -1,13 +1,14 @@
|
||||
import sys
|
||||
sys.path.insert(0, '.')
|
||||
|
||||
from flask import Flask, render_template
|
||||
from flask import Flask, render_template, redirect, url_for
|
||||
from flaskext.script import Manager
|
||||
from flaskext.sqlalchemy import SQLAlchemy
|
||||
from flaskext.debugtoolbar import DebugToolbarExtension
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config['DEBUG_TB_INTERCEPT_REDIRECTS'] = True
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
|
||||
db = SQLAlchemy(app)
|
||||
|
||||
@@ -23,7 +24,16 @@ def index():
|
||||
ExampleModel.query.get(1)
|
||||
return render_template('index.html')
|
||||
|
||||
@app.route('/redirect')
|
||||
def redirect_example():
|
||||
|
||||
response = redirect(url_for('index'))
|
||||
response.set_cookie('test_cookie', '1')
|
||||
return response
|
||||
|
||||
if __name__ == "__main__":
|
||||
db.create_all()
|
||||
|
||||
manager = Manager(app)
|
||||
manager.run()
|
||||
|
||||
|
||||
@@ -4,5 +4,6 @@
|
||||
</head>
|
||||
<body>
|
||||
<h1>Flask-debug-toolbar</h1>
|
||||
<a href="{{ url_for('redirect_example') }}">Redirect example</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user