URL routing

We added two additional functions and paired them up with the appropriate app.route() route in chapter9_2.py:

...
@app.route('/')
def index():
return 'You are at index()'

@app.route('/routers/')
def routers():
return 'You are at routers()'
...

The result is that different endpoints are passed to different functions:

$ http GET http://172.16.1.173:5000/
...

You are at index()

$ http GET http://172.16.1.173:5000/routers/
...

You are at routers()

Of course, the routing would be pretty limited if we have to keep it static all the time. There are ways to pass variables from the URL to Flask; we will look at an example in the next section.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.91.47