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

SQL-based searching


In any web application, it is important to be able to search the database for records based on some criteria. In this recipe, we will go through how to implement basic SQL-based searching in SQLAlchemy. The same principle can be used to search any other database system.

Getting ready

We have been implementing some level of search in our catalog application from the beginning. Whenever we show the product page, we search for a specific product using its ID. We will now take it to a more advanced level and search on the basis of name and category.

How to do it…

The following is a method that searches in our catalog application for name, price, company, and category. We can search for any one or multiple criterion (except for the search on category, which can only be searched alone). Notice that we have different expressions for different values. For a float value in price, we can search for equality, while in the case of a string, we can search using like. Also, carefully note...