registry.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:gru 作者: similarweb 项目源码 文件源码
def _setup_blueprint(self, module_name, module_ref):
        root_dir = os.path.dirname(inspect.getabsfile(module_ref))
        kwargs = {}
        # Register templates
        template_folder = os.path.join(root_dir, 'templates')
        if os.path.isdir(template_folder):
            kwargs.update({'template_folder': 'templates'})
        # Register static files, if any
        static_folder = os.path.join(root_dir, 'static')
        if os.path.isdir(static_folder):
            kwargs.update({
                'static_folder': 'static',
                'static_url_path': '/static/plugins/{}'.format(module_name)
            })

        # Generate blueprint
        blueprint = flask.Blueprint(module_name, module_name, **kwargs)

        # Add the plugin_static() helper function to the
        # template context
        @blueprint.context_processor
        def static_processor():
            def plugin_static(filename):
                return flask.url_for('{}.static'.format(module_name), filename=filename)
            return dict(plugin_static=plugin_static)

        # Blueprint done, return it
        return blueprint
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号