Performance: Redirect and abort functions
MEDIUM IMPACT
This concept affects the server response time and how quickly the browser can start rendering the next page or error message.
from flask import Flask, redirect, abort app = Flask(__name__) @app.route('/old') def old(): return redirect('/new') @app.route('/error') def error(): abort(404)
from flask import Flask app = Flask(__name__) @app.route('/old') def old(): # Manually build redirect response response = app.make_response('', 302) response.headers['Location'] = '/new' return response @app.route('/error') def error(): # Return error page content manually return '<h1>404 Not Found</h1>', 404
| Pattern | Server Processing | Response Size | Network Delay | Verdict |
|---|---|---|---|---|
| Manual redirect and error handling | High (extra code execution) | Larger (full HTML or headers manually set) | Longer (more data to send) | [X] Bad |
| Using Flask redirect and abort | Low (optimized helpers) | Minimal (standard HTTP headers) | Shorter (less data, faster start) | [OK] Good |