开发者

Class-based (generic) views in Flask

开发者 https://www.devze.com 2023-03-02 03:43 出处:网络
What\'s the best way to write generic views using the Flask web framework? Does the @app.route decorator support ca开发者_如何转开发llable classes? Or am I thinking about this in entirely the wrong f

What's the best way to write generic views using the Flask web framework?

Does the @app.route decorator support ca开发者_如何转开发llable classes? Or am I thinking about this in entirely the wrong fashion?

Any help or advice would be greatly appreciated!


Starting with Python 2.6 you can apply the decorators to classes as well. There is no builtin pattern for callable classes because there are too many ways to implement them, but essentially the trick would be to override __call__ on the class and to have a wrapper decorator that instanciates the class.

I was planning on having a class-based-view extension but so far nobody came up with some good behavior for it :)

0

精彩评论

暂无评论...
验证码 换一张
取 消