Developing Web Applications with Python and Flask

Developing Web Applications with Python and Flask!

This course teaches the fundamentals of Flask by building a full-featured web application. Each chapter builds upon itself to achieve the goal of developing a stock portfolio app.

What will you build?

In this course, you'll build an app for tracking stock portfolios. You can think of it as a basic version of a brokerage site like Fidelity or TD Ameritrade. The app provides user management functionality (e.g., registration, login/logout, password reset) so that multiple users can access the app. After registering, users will be able to view and add new stocks to their portfolio.

An example of the Flask application that you'll be creating in this course can be found at:


Learning Objectives

Here are the key concepts that you will learn in each part of this course:

Part 1 - Flask Fundamentals

  1. Utilize Python 3 and Flask to create a web application
  2. Create view functions for handling requests to specific URLs (routes)
  3. Utilize the Jinja templating engine to add logic when generating HTML
  4. Process form data in a view function using the request proxy
  5. Store and retrieve data in a session for use between requests
  6. Write tests using pytest
  7. Utilize static files (sylesheets, images) for enhancing the look and feel of the app
  8. Create flash messages for displaying information to the user
  9. Log messages to a file to understand the operations of the web app

Part 2 - Structure

  1. Organize a Flask project into blueprints
  2. Create multiple configurations for your development, production, and testing environments
  3. Create an application factory function for initializing a Flask app
  4. Describe the steps for processing a request in Flask
  5. Explain how the application and request contexts work during request processing
  6. Utilize fixtures to help initialize the state for running tests

Part 3 - Database

  1. Create a SQLite database to store data
  2. Utilize Flask-SQLAlchemy to interact with the SQLite database
  3. Create custom CLI commands for populating data into the database

Part 4 - User Management

  1. Utilize TDD to incrementally add functionality to a Flask app
  2. Handle user registration in Flask
  3. Explain how to mitigate CSRF and XSS attacks in Flask
  4. Send emails using Flask-Mail
  5. Confirm users' email addresses using unique links emailed to them
  6. Implement 'forgot your password' functionality
  7. Create a user profile page

Part 5 - Stocks

  1. Display and add stocks to a user's portfolio
  2. Utilize monkeypatching to test working with an external API
  3. Retrieve stock data from an external API
  4. Display charts of stock prices using Chart.js

Part 6 - Deployment

  1. Deploy a Flask app to Heroku
  2. Utilize SendGrid for sending emails in production

Tools and Technologies

  1. Python
  2. Flask
  3. pytest
  4. SQLite
  5. Gunicorn
  6. Heroku
  7. SendGrid

As the culmination of this course, we'll deploy the Flask application to the web using Heroku.


This course is intended for people with some experience with Python.

No prior experience with other web frameworks (Django, Pyramid, FastAPI, etc.) is required.


  • Current version: 1.1.0
  • Last updated: December 15th, 2020
  • AuthorPatrick Kennedy

What will you learn?

Part 1

Flask is considered a micro-framework, as it provides the core pieces of functionality needed for a web framework.

The first section of this course focuses on those core pieces:

  • View functions
  • Jinja templates
  • Forms
  • Sessions
  • Static files
  • Flash messages
  • Logging

Additionally, you'll learn how to write tests for a Flask application using pytest.

Part 2

The second section of this course focuses on structuring a Flask application using blueprints.

In this section, you'll learn how to create different configurations for different environments -- e.g., development, testing, and production. We'll dive into how the Application Factory design pattern can be applied to Flask to easily create a Flask application as well.

This section also provides a deep-dive into how Flask processes requests and how the application and request contexts are handled during a request.

Finally, you'll learn how fixtures in pytest can help create the initial state for running tests.

Part 3

The third section of this course focuses on using Flask-SQLAlchemy to:

  • create models for the tables in the database
  • store and retrieve data in the database

In addition, we'll look at how to create custom CLI commands in Flask to populate the database with data.

Part 4

Starting with the fourth section of this course, we'll utilize Test-Driven Development (TDD) to incrementally add functionality to the Flask app.

This section focuses on managing the users of the app:

  • Registering new users
  • Logging users in and out
  • Sending emails with Flask-Mail
  • Confirming users' email addresses using unique links emailed to them
  • Implementing 'forgot your password' functionality
  • Presenting a user profile page

In addition, you'll learn about how to mitigate CSRF and XSS attacks.

Part 5

The fifth section of this course focuses on working with stock data.

We'll look at how to display the stock portfolio for each user and how to add new stocks.

You'll learn about monkeypatching for testing an external API. Then, we'll dive into pulling in stock data from an external API.

This section culminates with creating charts of the historical stock prices using Chart.js.

Part 6

The sixth section of this course focuses on deploying the app to Heroku and configuring SendGrid for sending emails.

Table of Contents

Table of contents from Developing Web Applications with Python and Flask:

Part 1
Part 2
  • Blueprints
  • Configuration
  • Application Factory
  • Flask Under the Hood
  • Pytest Fixtures
  • Error Pages
Part 3
  • Database Relationships
  • Databases
  • Database Migrations
  • Database Testing
  • Flask CLI

Part 4
  • User Model
  • User Registration
  • Security
  • Login and Logout
  • Navigation
  • Sending Email
  • Confirming Email Addresses
  • Password Reset via Email
  • User Profile
  • Change Password
  • Resend Email Confirmation
Part 5
  • Stock Model
  • Adding Stock Data
  • Monkeypatching
  • Retrieving Stock Data
  • Chart.js
  • Displaying Stock Charts
Part 6
  • Deploying to Heroku
  • Conclusion

Join our mailing list to be notified about course updates and new tutorials.