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 :)
精彩评论