-
-
Save somangshu/c2a98a8874b09b4578bc05d20ae9832e to your computer and use it in GitHub Desktop.
Environment variables in python flask
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
APP_ENV=local | |
DEBUG=True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
import os | |
import webconfig | |
environment = os.getenv('APP_ENV') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Flask==1.0.2 | |
python-dotenv=0.10.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/**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