-
-
Save roganjoshp/ed770bd17958a1eccc9248472b8e0a6e to your computer and use it in GitHub Desktop.
Flask with envvars
This file contains hidden or 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
SECRET_KEY = '2a057dd2f0844f5a928578032c5b9955' | |
DB_URL = 'postgresql+psycopg2://postgres:######@127.0.0.1/so_test' |
This file contains hidden or 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 | |
from config import Config | |
def create_app(): | |
app = Flask(__name__) | |
app.config.from_object(Config) | |
# Other stuff | |
return app |
This file contains hidden or 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
import os | |
import uuid | |
from dotenv import load_dotenv | |
basedir = os.path.abspath(os.path.dirname(__file__)) | |
load_dotenv(os.path.join(basedir, '.env')) | |
class Config: | |
SECRET_KEY = os.environ.get('SECRET_KEY', uuid.uuid4().hex) | |
DB_URL = os.environ.get('DB_URL') | |
# Other general config | |
SQLALCHEMY_DATABASE_URI = DB_URL | |
SQLALCHEMY_TRACK_MODIFICATIONS = False | |
SESSION_TYPE = 'sqlalchemy' | |
SESSION_SQLALCHEMY_TABLE = 'sessions' | |
SCHEDULER_API_ENABLED = True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment