Skip to content

Trigger a function for all the endpoint ? #5114

Closed Answered by abhint
BobSquarePants asked this question in Q&A
Discussion options

You must be logged in to vote
from flask import Flask, request

app = Flask(__name__)

@app.before_request
def before_request():
    endpoints = ['/endpoint1', '/endpoint2']
    if request.endpoint in endpoints:
        print('Code executed for endpoint:', request.endpoint)

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@BobSquarePants
Comment options

Answer selected by BobSquarePants
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants