问题
In Flask(or werkzeug), how can I get the view function when all I have is the Rule? (or the Endpoint from that rule)?
回答1:
Werkzeug only stores a map of rules, each of which has an endpoint. Flask adds to Werkzeug by associating each endpoint with a function. Use the app.view_functions
dict to get the view function from the endpoint name.
# assuming r is a Rule
f = app.view_functions[r.endpoint]
来源:https://stackoverflow.com/questions/32812431/how-can-i-get-the-view-function-from-an-endpoint-rule