Flask – Routing

Modern web frameworks use the routing technique to help a user remember application URLs. It is useful to access the desired page directly without having to navigate from the home page.

The route() decorator in Flask is used to bind URL to a function. For example −

def hello_world():
   return hello world
Here, URL '/hello' standard is bound to the hello_world() work. Thus, if a client visits http://localhost:5000/hello URL, the output of the hello_world() capacity will be rendered in the program.

The add_url_rule() function of an application article is additionally accessible to tie a URL with a capacity as in the above model, route() is used.

A decorator’s purpose is also served by the following representation −

def hello_world(): return hello world app.add_url_rule(‘/’, hello’, hello_world)