Nestable Blueprint无法正常工作

时间:2018-02-23 06:20:13

标签: python design-patterns flask

我想使用蓝图嵌套,以便类似的蓝图可以有类似的$("[id^='toggle_']").on("click", function() { console.log("clicked: " + $(this).attr("id").replace("toggle_", "").toString()); }); $("#toggle_google").on("click", function() { console.log("clicked google"); }); $("#toggle_google").trigger("click"); $("#toggle_google").click(); 等(以及漂亮的网址名称间距)。

我知道烧瓶本身不支持此功能。

但是,this issue提到了一种方法:

@similar.before_request

尝试以上操作无效,并给我404.

我有一个文件,它定义了一个蓝图,如:

class NestableBlueprint(Blueprint):
    """
    Hacking in support for nesting blueprints, until hopefully https://github.com/mitsuhiko/flask/issues/593 will be resolved
    """

    def register_blueprint(self, blueprint, **options):
        def deferred(state):
            url_prefix = (state.url_prefix or u"") + (options.get('url_prefix', blueprint.url_prefix) or u"")
            if 'url_prefix' in options:
                del options['url_prefix']

            state.app.register_blueprint(blueprint, url_prefix=url_prefix, **options)
        self.record(deferred)

在底部,我有:

base_blueprint = Blueprint("BASE", __name__, url_prefix='/v0.1')

Admin.py定义为:

from .Admin import admin_base_blueprint
admin_base_blueprint.register_blueprint(base_blueprint,
                                        url_prefix='/admin')

当我尝试访问admin_base_blueprint = NestableBlueprint('admin', __name__) @admin_base_blueprint.route('/', methods=['GET']) def admin_echo_time(): """ Just a function to echo current time. May be useful for testing if servers are up. :return: current date """ return datetime.now() 时,它会给我一个404.

我也试过https://stackoverflow.com/a/36326234/2670775。在这种情况下,我能够获取url名称间距,但是像before_request这样的蓝图函数不会被调用。

我的烧瓶版本是0.12.2

0 个答案:

没有答案