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

Adding the Account and Dashboard pages


We want to add two new pages to our application: 'Dashboard', where all requests from the patrons of a particular restaurant can be seen, and 'Account', where the restaurants can manage their tables and view the URLs that they need to make available on the tables.

We could simply create two new .html files in our templates directory and write the HTML from scratch. But we'll soon find that we need many of the same elements from our home page (at the very least, the parts that include and configure Bootstrap). Then we'll be tempted to just copy and paste the HTML from the home page and start working on our new page from there.

Introducing Jinja templates

Copying and pasting code is usually a sign that something is wrong. In application code, it means that you haven't modularized your code well, and you need to create some more classes and probably add a couple of import statements to include the reused code wherever it is needed. Using Jinja, we can follow...