python - Do I need to name the url when using app.add_url_rule? -


from flask docs:

def index():     pass app.add_url_rule('/', 'index', index) 

it says:

endpoint – endpoint registered url rule. flask assumes name of view function endpoint

indeed, if app.add_url_rule('/', none, index) seems work fine. (i'm not sure of terminology , "endpoint" is.)

some further questions:

  1. is there reason specify second argument?

  2. is second argument indeed "endpoint"?

  3. what benefits/drawbacks of (not) specifying second argument?

  4. what if same name used in url rule? first overwritten? intended?

in case, endpoint term valid url of application. wikipedia:

in service-oriented architecture, endpoint entry point service, process, or queue or topic destination

as naming urls - yes, optional. there benefits defining names. when using *url_for*() or redirect() example, can specify url's name shortcut. comes added benefit of allowing change url structure without changing every line of code interacts url, since references name.

so in example, reference index url this:

return redirect('index') 

for last question, i'm not sure happen. error when trying resolve url name. either way, there's no reason define 2 different urls same name.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -