经过一段时间的红宝石工作后,我回到了python。 我正在使用烧瓶框架。
如何在启动控制器操作时实现过滤器以在请求上运行方法,而无需在每个控制器中放入相同的代码? 我的第一个猜测是构建某种装饰器(例如@before_request,但这似乎并不是乍一看)。 我刚刚得到(重新)了解python,并且几乎没有什么东西可以接触到,所以任何输入都会被赞赏。 相当于Rails中的before_filter或Sinatra中的before do方法。
After some time working with ruby, I'm back to python. I'm working with the flask framework.
How do I implement a filter to run a method on the request at the start the controller action without putting the same code in every controller? My first guess is to construct a decorator of some sort(e.g. @before_request but that did not seem it on first glance). I'm just getting (re)acquainted with python and there are few things just out of reach, so any input appreciated. The equivalent is a before_filter in Rails or before do method in Sinatra.
最满意答案
有一个@app.before_request构造函数可用,如文档中给出的SQLite模式所示。 这是针对每个请求运行的。
There is a @app.before_request constructor available as shown in the SQLite pattern given in the docs. This is run on every request.
更多推荐
发布评论