Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 是否定义了路线的顺序?_Python_Python 2.7_Flask - Fatal编程技术网

Python 是否定义了路线的顺序?

Python 是否定义了路线的顺序?,python,python-2.7,flask,Python,Python 2.7,Flask,在我的视图中,我的设置与以下类似: @app.route("/test") def test(): ... @app.route("/<to>") def page(to): ... @app.route(“/test”) def test(): ... @附件路线(“/”) def页面(至): ... 在访问“/test”url时,似乎始终会调用示例中的函数test。这也是我想要的。但我在文档中找不到这种行为。是否定义的名称总是优先于变量?还是定义的顺序很重要?

在我的视图中,我的设置与以下类似:

@app.route("/test")
def test():
    ...
@app.route("/<to>")
def page(to):
    ...
@app.route(“/test”)
def test():
...
@附件路线(“/”)
def页面(至):
...
在访问“/test”url时,似乎始终会调用示例中的函数test。这也是我想要的。但我在文档中找不到这种行为。是否定义的名称总是优先于变量?还是定义的顺序很重要?我能否以任何方式设置优先级以确保将来不会中断?

Flask用于处理路由,它根据路由中的可变零件数量来订购路由

/test
没有可变部分,而
/
有可变部分,因此它将首先尝试匹配
/test

目前,订购是根据以下文件进行的:

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:
    """

权重由路径的静态部分(权重大于动态部分,首先匹配较短路径)或转换器特定权重(数字转换器在基于字符串的转换器之前排序,在任意路径转换器之前排序)确定。

I在何处询问权重,但看到了您的编辑。回答得好!