Python flask.json 模块,load() 实例源码

我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用flask.json.load()

项目:flask-reactjs    作者:lassegit    | 项目源码 | 文件源码
def get_assets(asset_type):
    path = os.path.join(current_app.root_path, current_app.config['TEMPLATE_FOLDER'], 'assets.json')
    assets = json.load(open(path, 'r'))
    output = ''

    if asset_type == 'css':
        output = '<link rel="stylesheet" href="{0}">'.format(assets['style']['css'])

    elif asset_type == 'js':
        manifest = assets['manifest']['js']
        manifest = manifest[1:]

        manifest_file = open(os.path.join(current_app.root_path, current_app.config['STATIC_FOLDER'], manifest), 'r')
        output += '<script>' + manifest_file.read() + '</script>'
        manifest_file.close()

        output += '<script src="{0}"></script>'.format(assets['vendor']['js'])
        output += '<script src="{0}"></script>'.format(assets['app']['js'])

    return jinja2.Markup(output)
项目:drift    作者:dgnorth    | 项目源码 | 文件源码
def init_app(self, app):
        self.app = app

        # Schema files are stored in 'schemas' folders. By default, we will
        # do a recursive search from the application root.
        self._schemas = {}
        schema_root_folder = app.config.get('JSONSCHEMA_ROOT')
        if not schema_root_folder:
            schema_root_folder = os.path.join(app.instance_path, "..")
        for root, dirs, files in os.walk(schema_root_folder):
            head, tail = os.path.split(root)
            if tail != "schemas":
                continue

            loaded = []
            for filename in files:
                schema_file = os.path.join(root, filename)
                if schema_file.lower().endswith(".json"):
                    with open(schema_file) as f:
                        short_name, ext = os.path.splitext(filename)
                        self._schemas[short_name] = json.load(f)
                        loaded.append(short_name)

            if loaded:
                log.info("Loading %s from %s", loaded, root)

        app.extensions['jsonschema'] = self
项目:rc-niceties    作者:mjec    | 项目源码 | 文件源码
def get(self, url):
        for matcher in self.url_matches:
            if matcher[0].fullmatch(url):
                return SimpleNamespace(data=json.load(
                    open(os.path.join(app.root_path, 'mock/fixtures/' + matcher[1]))
                ))
        return SimpleNamespace(data={})
项目:api-manager    作者:nebula-orchestrator    | 项目源码 | 文件源码
def rabbit_login(rabbit_login_user, rabbit_login_password, rabbit_login_host, rabbit_login_port, rabbit_login_vhost,
                 rabbit_login_heartbeat):
    rabbit_connection = rabbit_connect(rabbit_login_user, rabbit_login_password, rabbit_login_host, rabbit_login_port,
                                       rabbit_login_vhost, rabbit_login_heartbeat)
    rabbit_connection_channel = rabbit_create_channel(rabbit_connection)
    return rabbit_connection_channel


# read config file at startup
# load the login params from envvar or auth.json file if envvar is not set
项目:perseids-manifold    作者:RDACollectionsWG    | 项目源码 | 文件源码
def __load_json__(self, filename):
        try:
            with open(filename) as filecontent:
                return load(filecontent)
        except FileNotFoundError:
            raise NotFoundError()
        except:
            raise DBError()
项目:nebula    作者:nebula-orchestrator    | 项目源码 | 文件源码
def rabbit_login():
    rabbit_connection = rabbit_connect(rabbit_user, rabbit_password, rabbit_host, rabbit_port, rabbit_vhost,
                                       rabbit_heartbeat)
    rabbit_connection_channel = rabbit_create_channel(rabbit_connection)
    return rabbit_connection_channel


# read config file at startup
# load the login params from auth.json file or envvar
项目:yafblog    作者:jifegg    | 项目源码 | 文件源码
def read_json(self):
        if not os.path.exists(self.fpath):
            self.write_json(self.finit)
        f = open(self.fpath, 'r');
        f.close()
        with open(self.fpath, 'r') as f:
            return json.load(f)