美文网首页
Flask项目下的app下的settings.py配置

Flask项目下的app下的settings.py配置

作者: Leo_23 | 来源:发表于2020-01-13 19:42 被阅读0次

    Flask项目下的app下的settings.py配置

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    
    __author__ = "leo"
    __time__ = "2020-01-12"
    
    import os
    
    BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    
    
    def get_db_uri(dbinfo):
        engine = dbinfo.get("ENGINE") or "sqlite"
        driver = dbinfo.get("DRIVER") or "sqlite"
        user = dbinfo.get("USER") or ""
        password = dbinfo.get("PASSWORD") or ""
        host = dbinfo.get("HOST") or ""
        port = dbinfo.get("PORT") or ""
        name = dbinfo.get("NAME") or ""
        return '{}+{}://{}:{}@{}:{}/{}'.format(engine, driver, user, password, host, port, name)
    
    
    class Config:
        DEBUG = False
        TESTING = False
        SQLALCHEMY_TRACK_MODIFICATIONS = False
    
    
    class DevelopConfig(Config):
        DEBUG = True
        dbinfo = {
            "ENGINE": "mysql",
            "DRIVER": "pymysql",
            "USER": "root",
            "PASSWORD": "",
            "HOST": "localhost",
            "PORT": "3306",
            "NAME": "flask",
    
        }
        SQLALCHEMY_DATABASE_URI = get_db_uri(dbinfo)
    
    
    class TestConfig(Config):
        TESTING = True
        dbinfo = {
            "ENGINE": "mysql",
            "DRIVER": "pymysql",
            "USER": "root",
            "PASSWORD": "",
            "HOST": "localhost",
            "PORT": "3306",
            "NAME": "flask",
    
        }
        SQLALCHEMY_DATABASE_URI = get_db_uri(dbinfo)
    
    
    class StagingConfig(Config):
        dbinfo = {
            "ENGINE": "mysql",
            "DRIVER": "pymysql",
            "USER": "root",
            "PASSWORD": "",
            "HOST": "localhost",
            "PORT": "3306",
            "NAME": "flask",
    
        }
        SQLALCHEMY_DATABASE_URI = get_db_uri(dbinfo)
    
    
    class ProductConfig(Config):
        dbinfo = {
            "ENGINE": "mysql",
            "DRIVER": "pymysql",
            "USER": "root",
            "PASSWORD": "",
            "HOST": "localhost",
            "PORT": "3306",
            "NAME": "flask",
    
        }
        SQLALCHEMY_DATABASE_URI = get_db_uri(dbinfo)
    
    
    envs = {
        'develop': DevelopConfig,
        'testing': TestConfig,
        'stage': StagingConfig,
        'product': ProductConfig,
        'default': DevelopConfig,
    }
    
    

    相关文章

      网友评论

          本文标题:Flask项目下的app下的settings.py配置

          本文链接:https://www.haomeiwen.com/subject/upunactx.html