How can I get the view function from an endpoint/rule?

余生颓废 提交于 2020-01-06 11:49:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!