At times, we might have to parse the various parts of a URL in different parts. For example, our URL can have an integer part, a string part, a string part of specific length, slashes in the URL, and so on. We can parse all these combinations in our URLs using URL converters. In this recipe, we will see how to do this. Also, we will learn how to implement pagination using the Flask-SQLAlchemy extension.
We have already seen several instances of basic URL converters. In this recipe, we will look at some advanced URL converters and learn how to use them.
Let's say we have a URL route defined as follows:
@app.route('/test/<name>') def get_name(name): return name
Here, 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...