URL routing

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

$ cat chapter9_2.pyfrom flask import Flaskapp = Flask(__name__)@app.route('/')def index():    return 'You are at index()'@app.route('/routers/')def routers():    return 'You are at routers()'if __name__ == '__main__':    app.run(host='0.0.0.0', debug=True)

The result is that different endpoints are passed to different functions. We can verify this with two http requests:

# Server$ python chapter9_2.py# Client$ 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 will be pretty limited if we have to keep it static all the time. There are ...

Get Mastering Python Networking - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.