Book Image

Flask Framework Cookbook

By : Shalabh Aggarwal
Book Image

Flask Framework Cookbook

By: Shalabh Aggarwal

Overview of this book

Table of Contents (19 chapters)
Flask Framework Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

URL routing and product-based pagination


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.

Getting ready

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.

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, 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...