FLASK is a micro framework. But you can do bg projects on FLASK. The flexibility is awesome. But there are no defined structure. I had hard time figuring one out. So, after hundreds of articles I have come up with this structure. This structure was followed for an AI based NLU API microservice project. I am uploading the basic structure to start up any FLASK project. You can call it, the basic skeleton of a FLASK project for maintainable big applications.
- git clone https://github.com/anuragbhattacharjee/flask-structure.git
- python3 -m venv {your-app-name}-venv
- source {your-app-name}-venv/bin/activate
- pip install -r requirements.txt
- flask run
pip freeze > requirements.txt
More info: https://pip.pypa.io/en/stable/reference/pip_freeze/
- Set Env varibales:
For Mac/Linux:
export FLASK_ENV=development
export FLASK_DEBUG=1
For windows:
set FLASK_ENV=development
set FLASK_DEBUG=1
- By using python-dotenv ( recommended )
> pip install python-dotenv
create a .flaskenv file in your project
in .flaskenv add these lines:
FLASK_ENV=development
FLASK_DEBUG=1
Check if environement variables are set properly: For Linux:
printenv FLASK_ENV
printenv FLASK_DEBUG
I have added all the to .gitignore so that the repository don't get bloated. It's a standard practice. Please add all these to your .gitignore:
{your-app-name}-venv
__pycache__
.flaskenv
*.log
*.pot
*.pyc
*/*/*/__pycache__/
*/*/__pycache__/
*/__pycache__/