How to organize a relatively large Flask application?

前端 未结 6 1943
渐次进展
渐次进展 2020-12-12 09:57

I\'m building my first Flask app and I can\'t figure out a good, clean Pythonic way of organizing my application. I don\'t want to have everything in a single .py file as in

6条回答
  •  囚心锁ツ
    2020-12-12 10:20

    I worked on a social network built on top of Flask. The special thing about my project was that the server is purely serving API endpoints and the frontend is a one-page Backbone app. The Flask structure I took is the following:

    ├── app │ ├── api
    │ │ ├── auth.py │ │ └── ... │ ├── app.py │ ├── common │ │ ├── constants.py │ │ ├── helpers.py │ │ ├── response.py │ │ └── ... │ ├── config.py │ ├── extensions.py │ ├── frontend │ │ └── controllers.py │ ├── static │ │ └── ... │ ├── templates │ │ ├── app.html │ │ └── ... │ └── users │ ├── UserConstants.py │ ├── UserForms.py │ ├── UserHelpers.py │ ├── UserModels.py │ └── __init__.py ├── alembic | ├── version │ └── ... ├── tests │ └── ...

    You can read the more in-depth post I wrote on the topic here. I found it to be much more intuitive to separate different functional areas to its own folder.

    I worked on the code a while ago and open sourced it completely! You can check it out on github.

提交回复
热议问题