Class-based (generic) views in Flask
Asked Answered
A

1

5

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

Does the @app.route decorator support callable classes? Or am I thinking about this in entirely the wrong fashion?

Any help or advice would be greatly appreciated!

Amerce answered 3/5, 2011 at 13:7 Comment(0)
P
11

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 :)

Prim answered 3/5, 2011 at 13:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.