This is the werkzeug route optimization feature. See Map.add , Map.update and 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
There are self.arguments - current arguments, self._weights - the depth of the path.
For '/<var_1>/<var_2>/<var3>/' we have (True, -3, [(1, 100), (1, 100), (1, 100)]) . There is (1, 100) - the default string argument with a maximum length of 100.
For '/static/<path:filename>' we have (True, -2, [(0, -6), (1, 200)]) . There is (0, 1) - path non argument string length static , (1, 200) - the length of the argument string max length 200.
Therefore, I did not find a beautiful way to set my own implementation of Map for Flask.url_map or set priority for a map rule. Solutions:
- Setting the
Flask application as app = Flask(static_path='static', static_url_path='/more/then/your/max/variables/path/depth/static') . - Change
@app.route('/<var_1>/<var_2>/<var3>/') to @app.route('/prefix/<var_1>/<var_2>/<var3>/') . - Add your own converter and use it as
@app.route('/<no_static:var_1>/<var_2>/<var3>/') . - Import
werkzeug.routing , create your own map implementation, change werkzeug.routing.Map to your own implementation, import Flask . - Use the server as in production.
tbicr
source share