Flask project structure


Question

I want to know what is the best folder structure to follow when using Flask. I want to achieve the following:

/myproject runserver.py /app1 ... /app2 ....

And of course I want to share my database configuration with all my apps. How can I achieve this? In the documentation they always talk of ONE app

PD: I'm comming from django. PD2: I've also read this: http://flask.pocoo.org/docs/blueprints/ and this: http://flask.pocoo.org/docs/patterns/packages/#modules-and-resources

1
0
1/12/2013 10:38:38 PM

I found myself that best for me is to divide an application into blueprints. That is, split the whole thing not into separate WSGI applications but rather into these Flask-like objects which get registered in the Flask app. They provide possibilities to register errorhandlers, template context processors, etc. for views registered as endpoints of blueprint or for whole application - your choice.

Sharing of database connection object can be done through use of class with name "request_globals_class" (it must be declared in your application class which of course inherits Flask). When you provide an attribute for this class it is then accessible for a view (or whatever runs in request handling context) as an attribute of flask.g object.

3
1/12/2013 11:09:29 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon