[1999] I am new in Python Web Development. Looking for the best practice about the project file/folder structure and could not found any. Only found piece by piece from tutorial.
Thinking it would be worth to have my own Python Flask boilerplate from the ideas and technique in below references.
Also it would be great to share this out to anyone who like it.
This boilerplate is using library list here but feel free to add any to meet your requirement.
- Python 3.7
- dotenv
- flask
- flask-sqlalchmy
- flask-wtf
- gunicorn
if you plan to use PostgreSQL, this required
- psycopg2
$ tree -a --dirsfirst
├── nameyourapp
│ ├── api
│ │ ├── __init__.py
│ │ └── routes.py
│ ├── nameyourmodule
│ │ ├── static
│ │ ├── templates
│ │ ├── __init__.py
│ │ └── routes.py
│ ├── static
│ │ ├── css
│ │ │ └── style.css
│ │ ├── img
│ │ └── js
│ ├── templates
│ │ ├── index.html
│ │ └── layout.html
│ ├── extensions.py
│ ├── forms.py
│ ├── __init__.py
│ ├── models.py
│ ├── routes.py
│ └── settings.py
├── .env
├── .flaskenv
├── .gitignore
├── Pipfile
├── Pipfile.lock
├── Procfile
├── README.md
└── wsgi.py- download this repository
- rename
nameyourappaccording to your project. - update and develop source code.
- If you use
pipenv, you can just$ pipenv installall basic library will be installed. - In the development environment, you can run
flask runto start your app.
wsgi.pywill be the entry point for the production environment..envwhere you put all sensitive settings/keys like TOKEN, API-KEY.flaskenvwhere put Flask variable e.g.
FLASK_APP=nameyourapp
FLASK_ENV=development
FLASK_DEBUG=true
nameyourapp/__initi__.pyis the starting point.nameyourapp/models.pywhere you define your data tables.nameyourapp/routes.pyyour Blueprint module/functionnameyourapp/settings.pyput all settings/configurations.apiis the sample Blueprint module.nameyourmoduleput any of your separate module here.
- Demystifying Flask’s Application Factory, Hackers & Slacker
- Organizing Flask Apps with Blueprints, Hackers & Slackers
- Organizing a Flask Project Beyond Single File, Pretty Printed YouTube Channel
- Deploy a Flask App to Heroku With a Postgres Database [2019], Pretty Printed YouTube Channel
- Python Flask Tutorial: Full-Featured Web App Part 11 - Blueprints and Configuration, Corey Schafer YouTube Channel
- Python Flask Tutorial: Full-Featured Web App Part 5 - Package Structure, Corey Schafer YouTube Channel