'before

编程入门 行业动态 更新时间:2024-10-27 22:34:36
'before_filter'相当于烧瓶('before_filter' equivalent w/ flask)

经过一段时间的红宝石工作后,我回到了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.

更多推荐

本文发布于:2023-08-04 04:41:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1409455.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!