July 2019
Beginner to intermediate
302 pages
9h 38m
English
Let's say we have a URL route defined as follows:
@app.route('/test/<name>')
def get_name(name):
return name
Here, the URL, http://127.0.0.1:5000/test/Shalabh, will result in Shalabh being parsed and passed in the name argument of the get_name method. This is a Unicode or string converter, which is the default one and need not be specified explicitly.
We can also have strings with specific lengths. Let's say we want to parse a URL that may contain a country code or currency code. Country codes are usually two characters long, and currency codes are three characters long. This can be done as follows:
@app.route('/test/<string(minlength=2,maxlength=3):code>')
def get_name(code):
return code
This will match both US and USD ...