Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/338.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_Flask - Fatal编程技术网

Python 你是如何看待你的工作的?

Python 你是如何看待你的工作的?,python,flask,Python,Flask,endpoint这件事对我来说似乎很神奇。它的行为方式如下: 在单个文件中,可以通过('dothat')的url\u获取修饰方法dothat 使用,views.dothat可以通过('dothat')的url\u获取,当时我希望我必须提供完全限定的方法名称,如('myapp.views.dothat')的url\u中的 因此,如果不是完全限定的方法名,Flask将接受什么作为端点?Flask不使用端点的模块名。它只是默认为函数名 如果使用相同的名称注册两个不同的函数(例如,在两个不同的模块中),

endpoint
这件事对我来说似乎很神奇。它的行为方式如下:

  • 在单个文件中,可以通过('dothat')的
    url\u获取修饰方法
    dothat
  • 使用,
    views.dothat
    可以通过('dothat')
    url\u获取,当时我希望我必须提供完全限定的方法名称,如('myapp.views.dothat')的
    url\u中的
  • 因此,如果不是完全限定的方法名,Flask将接受什么作为端点?

    Flask不使用端点的模块名。它只是默认为函数名

    如果使用相同的名称注册两个不同的函数(例如,在两个不同的模块中),将引发
    AssertionError
    异常:

    flask.url_for(endpoint, **values)
    
    在以下情况下,可以指定显式端点名称:

    raise AssertionError('View function mapping is overwriting an '
                         'existing endpoint function: %s' % endpoint)
    
    见:

    端点–已注册URL规则的端点。Flask本身将视图函数的名称作为端点


    注册视图(使用
    @app.route()
    decorator)时,将确定端点名称(除非明确设置),并与路由注册一起存储
    url\u for()
    使用路由注册查找根据该名称注册的所有路由,并查找最适合您也传递给
    url\u for()的参数的路由。

    当两个函数具有相同名称时会发生什么,但是它们在不同的模块中吗?@aitchnyu:那么你需要给一个显式的
    端点
    值。
    @app.route('/', endpoint='alt_homepage')
    def homepage():
        pass