fantasy/__init__.py
def smart_account(app):
    """尝试使用内置方式构建账户"""
    if os.environ['FANTASY_ACTIVE_ACCOUNT'] == 'no':
        return

    from flask_security import SQLAlchemyUserDatastore, Security

    account_module_name, account_class_name = os.environ[
        'FANTASY_ACCOUNT_MODEL'].rsplit('.', 1)

    account_module = importlib.import_module(account_module_name)
    account_class = getattr(account_module, account_class_name)

    role_module_name, role_class_name = os.environ[
        'FANTASY_ROLE_MODEL'].rsplit('.', 1)
    role_module = importlib.import_module(role_module_name)
    role_class = getattr(role_module, role_class_name)

    r = True if os.environ[
                    'FANTASY_ACCOUNT_SECURITY_MODE'] != 'no' else False

    Security(app,
             SQLAlchemyUserDatastore(
                 app.db, account_class, role_class),
             register_blueprint=r)
    pass
def smart_account(app):
    """尝试使用内置方式构建账户"""
    if os.environ['FANTASY_ACTIVE_ACCOUNT'] == 'no':
        return

    from flask_security import SQLAlchemyUserDatastore, Security

    account_module_name, account_class_name = os.environ[
        'FANTASY_ACCOUNT_MODEL'].rsplit('.', 1)

    account_module = importlib.import_module(account_module_name)
    account_class = getattr(account_module, account_class_name)

    role_module_name, role_class_name = os.environ[
        'FANTASY_ROLE_MODEL'].rsplit('.', 1)
    role_module = importlib.import_module(role_module_name)
    role_class = getattr(role_module, role_class_name)

    r = True if os.environ[
                    'FANTASY_ACCOUNT_SECURITY_MODE'] != 'no' else False

    Security(app,
             SQLAlchemyUserDatastore(
                 app.db, account_class, role_class),
             register_blueprint=r)
    pass
def smart_account ( app ) : if os . environ [ 'FANTASY_ACTIVE_ACCOUNT' ] == 'no' : return from flask_security import SQLAlchemyUserDatastore , Security account_module_name , account_class_name = os . environ [ 'FANTASY_ACCOUNT_MODEL' ] . rsplit ( '.' , 1 ) account_module = importlib . import_module ( account_module_name ) account_class = getattr ( account_module , account_class_name ) role_module_name , role_class_name = os . environ [ 'FANTASY_ROLE_MODEL' ] . rsplit ( '.' , 1 ) role_module = importlib . import_module ( role_module_name ) role_class = getattr ( role_module , role_class_name ) r = True if os . environ [ 'FANTASY_ACCOUNT_SECURITY_MODE' ] != 'no' else False Security ( app , SQLAlchemyUserDatastore ( app . db , account_class , role_class ) , register_blueprint = r ) pass
尝试使用内置方式构建账户
尝试使用内置方式构建账户