Saner routing for growing Flask applications
flask-via.soon.build
flask-via.soon.build
I really like Flask, but Flask's entire point is that it's a thin, user-friendly wrapper around Werkzeug. Werkzeug isn't my favorite low-level web framework for Python (that'd be WebOb), but the fact that it is trivial to dive into Werkzeug from Flask is Flask's killer feature: its whole raison d'être is that you can smoothly and cleanly replace Flask with your own application-specific Werkzeug middleware as you grow big.
So I guess the only thing that surprises me somewhat here is that the author has approached this as a way of scaling Flask up, rather than providing a clean way of moving Flask out in a way that eases transition to pure Werkzeug. I know that Flask has gradually been growing in some ways via its extensions, and maybe that is indeed its future. But I still think that Flask is best used as the training wheels to get a small app up quickly, and that gradually removing it as you grow is likely the best course of action. Otherwise, I think you'd likely be much better off using a framework like Django, with all the bells and whistles you need for any normal CRUD app, rather than rolling it all yourself in Flask in the first place.
app.add_url_rule('/endpoint', view_func=views.my_func, methods=['GET', 'POST'])Personally I treat the flask web as a really thin layer around my other more complex libraries (the core of the application). I use blueprints to group things together but I still try to make sure each of those is very simple, say - routing, data marshalling and session management - but anything more complex lives somewhere else.
Each function inside your views just gets a little data together and proxies it down to the real application.
As you say, maybe it gets more complex as the app grows in size, but to me that sounds like the app is trying to do too much. Over time I've learnt that thinking of your app as a 'flask application' (django, rails, whatever) means that it will grow in a way that's hard to maintain later.
As others have mentioned though, this is very similar to app.add_url_rule. Could you explain how this differs?