Implementing URL routing and product-based pagination
At times, we may encounter a problem where there is a need to parse the various parts of a URL differently. For example, a URL can have an integer part, a string part, a string part of a specific length, and slashes in the URL. 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.
Getting ready
We have already seen several instances of basic URL converters in this book. In this recipe, we will look at some advanced URL converters and learn how to use them.
How to do it...
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...