Book Image

Flask By Example

By : Gareth Dwyer
Book Image

Flask By Example

By: Gareth Dwyer

Overview of this book

This book will take you on a journey from learning about web development using Flask to building fully functional web applications. In the first major project, we develop a dynamic Headlines application that displays the latest news headlines along with up-to-date currency and weather information. In project two, we build a Crime Map application that is backed by a MySQL database, allowing users to submit information on and the location of crimes in order to plot danger zones and other crime trends within an area. In the final project, we combine Flask with more modern technologies, such as Twitter's Bootstrap and the NoSQL database MongoDB, to create a Waiter Caller application that allows restaurant patrons to easily call a waiter to their table. This pragmatic tutorial will keep you engaged as you learn the crux of Flask by working on challenging real-world applications.
Table of Contents (20 chapters)
Flask By Example
Credits
About the Author
Acknowledgements
About the Reviewers
www.PacktPub.com
Preface
Index

Creating a basic database web application


We will start by building a skeleton of our Crime Map application. It'll be a basic Flask application with a single page that:

  • Displays all the data in the crimes table of our database

  • Allows users to input data and stores this data in the database

  • Has a Clear button that deletes all the previously input data

Although what we will store and display can't really be described as crime data yet, we'll store it in the crimes table that we created earlier. We'll just use the description field for now, ignoring all the other ones.

The process of setting up the Flask application is very similar to what we did before. We will separate out the database logic into a separate file, leaving our main crimemap.py file for the Flask setup and routing.

Setting up our directory structure

On your local machine, change to the crimemap directory. If you created the database setup script on the server or made any changes to it there, make sure to sync the changes locally. Then...