0

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

danielrvt
  • 10,177
  • 20
  • 80
  • 121
  • It depends on the size of your project; I've been working on a project of a flask skeleton using the same kind of structure you mentioned, [Here is the link](https://github.com/albertogg/flask-bootstrap) If you are interested. I also think blueprints are the best way to divide the application. – albertogg Jan 13 '13 at 00:15
  • see here, Common folder/file structure in Flask app - Stack Overflow -> http://stackoverflow.com/questions/14415500/common-folder-file-structure-in-flask-app/14423811#14423811 – Mohammad Efazati Jan 22 '13 at 17:21

1 Answers1

3

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.

peroksid
  • 890
  • 6
  • 17
  • the thing is that I have a model that needs to access this db config outside a request context. How can I do that – danielrvt Jan 12 '13 at 23:16