Skip to content

Instantly share code, notes, and snippets.

@somangshu
Created January 6, 2019 14:12
Show Gist options
  • Save somangshu/c2a98a8874b09b4578bc05d20ae9832e to your computer and use it in GitHub Desktop.
Save somangshu/c2a98a8874b09b4578bc05d20ae9832e to your computer and use it in GitHub Desktop.
Environment variables in python flask
APP_ENV=local
DEBUG=True
from flask import Flask
import os
import webconfig
environment = os.getenv('APP_ENV')
Flask==1.0.2
python-dotenv=0.10.1
/**Create this file at the root*/
import os
from os.path import join, dirname
from dotenv import load_dotenv
/** this variable(IS_SERVER) will only be set on the production*/
is_prod = os.environ.get('IS_SERVER', None)
if not is_prod:
/**these settings will load up only when we are in a Local environment from the env file*/
dotenv_path = join(dirname(__file__), '.env')
load_dotenv(dotenv_path, verbose=True)
else:
/**these settings will load up only when we are in a server environment*/
APP_ENV = os.environ.get('APP_ENV')
DEBUG = os.environ.get('DEBUG')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment