June 2017
Intermediate to advanced
446 pages
10h 10m
English
As mentioned, we can also pass variables to the URL, as seen in the examples discussed in chapter9_3.py:
...@app.route('/routers/<hostname>')def router(hostname): return 'You are at %s' % hostname@app.route('/routers/<hostname>/interface/<int:interface_number>')def interface(hostname, interface_number): return 'You are at %s interface %d' % (hostname, interface_number)...
Note that in the /routers/<hostname> URL, we pass the <hostname> variable as a string; <int:interface_number> will specify that the variable should only be an integer:
$ http GET http://172.16.1.173:5000/routers/host1...You are at host1$ http GET http://172.16.1.173:5000/routers/host1/interface/1...You are at host1 interface 1# Throws exception$ http GET http://172.16.1.173:5000/routers/host1/interface/one ...
Read now
Unlock full access