Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's your folder layout for a Flask app divided in modules?

I am experimenting with Flask coming from Django and I really like it. There is just one problem that I ran into. I read the flask docs and the part about big applications or something like that and it explains a way to divide your project in packages, each one with its own static and templates folder as well as its own views module. the thing is that I cannot find a way that works to put the models in there using SQLAlchemy with the Flask extension. It works from the interactive prompt to create the tables, but when i use it inside the code it breaks. So I wanted to know how more experienced Flask developers solved this.

like image 857
actionAxolot Avatar asked May 22 '11 15:05

actionAxolot


People also ask

What is the structure of Flask?

Folder structure for a Flask appThat folder contains two folders, specifically named static and templates. The static folder contains assets used by the templates, including CSS files, JavaScript files, and images. In the example, we have only one asset file, main.


2 Answers

While I'm not ready to announce because I'm still actively working on refining the samples, you would probably benefit from the flask-skeleton project that I'm developing. I got tired of reinventing the wheel with regards to bootstrapping Flask websites so I started to a complete sample project that uses my best practices. I haven't added any unit tests yet, but this should be good enough for you to start with. Please send me feedback or suggestions if you come across any.

https://github.com/sean-/flask-skeleton/

like image 147
Sean Avatar answered Nov 03 '22 13:11

Sean


Actually I found out what I was looking for. Instead of importing flaskext.sqlalchemy on the main __init__ you import it in the model. After that you import the model in the main __init__ and with db.init_app() start it and pass the app configurations. It is not as flexible as the skeleton shown in @Sean post, but it was what I wanted to know. If i weren't toying around probably the skeleton would be the one I'd use.

like image 22
actionAxolot Avatar answered Nov 03 '22 13:11

actionAxolot