Use .env with Flask 1.*
pip install python-dotenv
Create .env inside you app/ folder file with content:
# FLASK_ENV=production FLASK_ENV=development FLASK_APP=app.py SECRET_KEY='your_very_secret_string'
Export to your app.py (or whatever you name it)
# Load .env https://github.com/theskumar/python-dotenv from dotenv import load_dotenv, find_dotenv load_dotenv(find_dotenv())
Now you can get any value from .env like this:
os.getenv('SECRET_KEY') or os.getenv('FLASK_ENV') ...
There are a lots of benefits from using .env inside you project: you ca easily separate environments for development purposes, write conditions depending on which mode you work with, deploy project in to production with easy and comfort... where are really tons of benefits!
For example. You've created .env from this article, now no need manually set environmental variables each time you need run your project, cd to your project and run:
...and you good to go.
For more detailed info watch following video: