您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Flask开发服务器中静态文件的URL路由冲突

Flask开发服务器中静态文件的URL路由冲突

这是werkzeug路线优化功能。见Map.addMap.update并且Rule.match_compare_key

def match_compare_key(self):
    """The match compare key for sorting.

    Current implementation:

    1. rules without any arguments come first for performance
    reasons only as we expect them to match faster and some
    common ones usually don't have any arguments (index pages etc.)
    2. The more complex rules come first so the second argument is the
    negative length of the number of weights.
    3. lastly we order by the actual weights.

    :internal:
    """
    return bool(self.arguments), -len(self._weights), self._weights

self.arguments-当前参数self._weights-路径深度。

因为'/<var_1>/<var_2>/<var3>/'我们有(True, -3, [(1, 100), (1, 100), (1, 100)])。有(1, 100)-最大长度为100的认字符串参数。

因为'/static/<path:filename>'我们有(True, -2, [(0, -6), (1, 200)])。有(0, 1)-路径非参数字符串长度static(1, 200)-路径字符串参数最大长度200。

因此,我找不到任何精美的方法来设置自己的Map实现Flask.url_map或为地图规则设置优先级。解决方案:

Python 2022/1/1 18:34:42 有212人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶