If you are new to the Flask environment perhaps this will look as completely new or random, but in essence, this is how you can have your “Environment configuration” setup for your development always there!

Short answer, the problem is if you don’t have this kind of setup, every time that you start your project you will need to add at least something like this to your environment:

$ export FLASK_APP=hello.py
$ export FLASK_ENV=development

Really?! Imagine doing this all the time.

And this is where the .env come to help you, let’s try to make it in 3 simple steps.


First — setup .env file.

First, we do need to have a .env file in the root folder of your project, if you have a Linux based system or Mac, inside the folder of your project just make:

touch .env

The chances are, if you can’t see the files in the folder it’s because all files like this are “extensions” and are hidden by default, but don’t worry.

Now let’s move to our second step. In order for this file get loaded, we need to add one library to our project that is: python-dotenv .


Second, let’s add the library that will use it.

In your project, imagining that you have your local python environment up and running, type:

pip install python-dotenv

_*Ps: If you don’t know what I just said, like how to setup your python environment I highly recommend first read this post: _https://itnext.io/beginning-with-flask-project-the-5-most-important-information-to-know-before-starting-f075e0fb0aec

Almost there, what we need to do now is create our basic setup environment, let’s add some information there:

DEBUG=True
FLASK_ENV=development
FLASK_APP=myapp.app.py
APP_SETTINGS=myapp.configuration.config.DevelopmentConfig
OAUTHLIB_INSECURE_TRANSPORT=true
SQLALCHEMY_ECHO=True
MAIL_USERNAME=myemail@gmail.com
MAIL_PASSWORD=my secret password
DATABASE_URL=sqlite:///development_database.db
## API key:
TWITTER_API_KEY=ds9f7sdf0s809df80s98d09f8s0
## API secret key:
TWITTER_API_SECRET_KEY=99asd8f08)C*)(8908dsC)*C)(80s9d808sC*()
## API Client ID:
FACEBOOK_API_CLIENT_ID=12312312312313123123
## API secret key:
FACEBOOK_API_SECRET_KEY=ssdf098809808sd76s7f646s45d46fsd

#flask #environment-setup #flask-framework #python #environment

Start using for your Flask project and stop using environment variables
4.20 GEEK