Flask: get current route
Simply use request.path
.
from flask import request
...
@app.route("/antitop/")
@app.route("/top/")
@requires_auth
def show_top():
... request.path ...
the most 'flasky' way to check which route triggered your view is, by request.url_rule
.
from flask import request
rule = request.url_rule
if 'antitop' in rule.rule:
# request by '/antitop'
elif 'top' in rule.rule:
# request by '/top'
Another option is to use endpoint variable:
@app.route("/api/v1/generate_data", methods=['POST'], endpoint='v1')
@app.route("/api/v2/generate_data", methods=['POST'], endpoint='v2')
def generate_data():
version = request.endpoint
return version