First a little bit about the flask code, time is limited, I slowly expand
The following is Add_url_rule code in flask source app.py.
It is mainly the correspondence between View_func-endpoint-url.
Flask, View_func and URL is not directly corresponding, is the URL first find endpoint, and then go through endpoint to find the corresponding View_func, a endpoint can only correspond to a view_func, in the register add_ Url_rule, if you do not specify endpoint, then endpoint will default to the function name, if the same endpoint in multiple URLs to register, there will be problems, see the code, will be judged before the corresponding to the present is not a, if not, Then throw an exception. It is certainly not possible to visit these URLs again. There is time to slowly expand this part of the content.
1 @setupmethod2 defAdd_url_rule (self, rule, endpoint=none, View_func=none, * *options):3 ifEndpoint isNone:4Endpoint =_endpoint_from_view_func (View_func)5options['Endpoint'] =Endpoint6 Methods7 ifMethods isNone:8Methods = GetAttr (View_func,'Methods', None)or('GET',)9 ifisinstance (Methods, string_types):Ten RaiseTypeError ('allowed methods has to be iterables of strings,' One 'For example: @app. Route (..., methods=["POST"])') AMethods = Set (Item.upper () forIteminchmethods) - -Required_methods = Set (GetAttr (View_func,'Required_methods', ())) the -Provide_automatic_options =getattr (View_func, - 'provide_automatic_options', None) - + ifProvide_automatic_options isNone: - if 'OPTIONS' not inchmethods: +Provide_automatic_options =True ARequired_methods.add ('OPTIONS') at Else: -Provide_automatic_options =False - - #ADD the required methods now. -Methods |=Required_methods - inRule = self.url_rule_class (rule, methods=methods, * *options) -Rule.provide_automatic_options =provide_automatic_options to + self.url_map.add (rule) - ifView_func is notNone: theOld_func =Self.view_functions.get (Endpoint) * ifOld_func is notNone andOld_func! =View_func: $ RaiseAssertionerror ('View function Mapping is overwriting an'Panax Notoginseng 'existing endpoint function:%s'%endpoint) -Self.view_functions[endpoint] = View_func
Endpoint issues in flask