flask_deprecate API¶
Submodules¶
flask_deprecate.flask_deprecate module¶
Business logic. Kept separate in case the project becomes larger for some reason in the future.
-
flask_deprecate.flask_deprecate.
deprecate_blueprint
(old_blueprint, new_blueprint=None, message='')[source]¶ Deprecates an every route on a blueprint by adding a header “WARNING” with a message.
If a url_prefix is set for the blueprint in either the blueprint init or the registration with the app, then an additional section on the header will appear saying the blueprint is deprecated. If a new_blueprint is also provided, the header will have additional info directing the client to the new URL. Note, that this will not automatically redirect the client.
The blueprint must be deprecated before registering it with the application
>>> from flask import Flask, Blueprint >>> app = Flask('myapp') >>> deprecated_bp = Blueprint('deprecated', 'deprecated') >>> new_bp = Blueprint('new', 'new') >>> deprecate_blueprint(old_blueprint, new_blueprint=new_bp) >>> app.register_blueprint(bp, url_prefix='/v1') >>> app.register_blueprint(new_bp, url_prefix='/v2')
Parameters: - old_blueprint (flask.Blueprint) – The blueprint to be deprecated
- new_blueprint (flask.Blueprint) – The new blueprint that will be replacing the old one (if applicable).
- message (str) – An extra message to append to the warning header
Return type: NoneType
-
flask_deprecate.flask_deprecate.
deprecate_route
(message='')[source]¶ Adds a Warning header to the response informing the client that the route is deprecated
from flask import Flask, Response from flask_deprecate import deprecate_route app = Flask('myapp') @app.route('/my_route') @deprecate_route() def deprecated_route(): return Response()
Parameters: message (str) – Additional information to provide to the client
Module contents¶
A tool for deprecating APIs in Flask. Injects a head for clients to catch and indicates the upgrade path.
-
flask_deprecate.
deprecate_blueprint
(old_blueprint, new_blueprint=None, message='')[source]¶ Deprecates an every route on a blueprint by adding a header “WARNING” with a message.
If a url_prefix is set for the blueprint in either the blueprint init or the registration with the app, then an additional section on the header will appear saying the blueprint is deprecated. If a new_blueprint is also provided, the header will have additional info directing the client to the new URL. Note, that this will not automatically redirect the client.
The blueprint must be deprecated before registering it with the application
>>> from flask import Flask, Blueprint >>> app = Flask('myapp') >>> deprecated_bp = Blueprint('deprecated', 'deprecated') >>> new_bp = Blueprint('new', 'new') >>> deprecate_blueprint(old_blueprint, new_blueprint=new_bp) >>> app.register_blueprint(bp, url_prefix='/v1') >>> app.register_blueprint(new_bp, url_prefix='/v2')
Parameters: - old_blueprint (flask.Blueprint) – The blueprint to be deprecated
- new_blueprint (flask.Blueprint) – The new blueprint that will be replacing the old one (if applicable).
- message (str) – An extra message to append to the warning header
Return type: NoneType
-
flask_deprecate.
deprecate_route
(message='')[source]¶ Adds a Warning header to the response informing the client that the route is deprecated
from flask import Flask, Response from flask_deprecate import deprecate_route app = Flask('myapp') @app.route('/my_route') @deprecate_route() def deprecated_route(): return Response()
Parameters: message (str) – Additional information to provide to the client