Developing Web Applications with Python and Flask

  • Updated December 15th, 2020
  • v1.1.0
Patrick Kennedy Patrick Kennedy

Developing Web Applications with Python and Flask!


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

What will you learn?

Select a Part

The first part 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.

Learning Objectives

  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

The second part focuses on structuring a Flask application using blueprints.

In this part, 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 part 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.

Learning Objectives

  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

The third part 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.

Learning Objectives

  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

Starting with the fourth part, we'll utilize Test-driven Development (TDD) to incrementally add functionality to the Flask app.

This part 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.

Learning Objectives

  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

The fifth part 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 part culminates with creating charts of the historical stock prices using Chart.js.

Learning Objectives

  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

The sixth part focuses on deploying the app to Heroku and configuring SendGrid for sending emails.

Learning Objectives

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

What do you need to know?

This course is intended for people with some experience with Python. No prior experience with other web frameworks (Django, Pyramid, FastAPI, etc.) is required.

Meet the Author

Patrick Kennedy

Patrick Kennedy

Patrick is a software engineer from the San Francisco Bay Area with experience in C++, Python, and JavaScript. His favorite areas of teaching are Vue and Flask. In his free time, he enjoys spending time with his family and cooking.

What developers are saying

The TestDriven.io courses are some of the best courses I've ever done for any language, any platform, any price range... just some of the most thorough and well-sourced courses around.

Just a word of thanks for doing such a great job with these training courses. The thorough, entire-lifecycle approach -- from implementation through test, coverage, quality, CI/CD, and all the rest -- is what separates these courses from other training material that I've completed. I'll be able to walk away from here with knowledge and skills that I can apply immediately at work -- and for that I'm grateful. It's a rare gift in an environment where so much 'training' is really just lightweight treatment that doesn't begin to scratch the surface of real, end-to-end software development. Really well done!

The TestDriven.io courses are worth 10 times what I paid for them.

I'm writing to thank you for all the tutorials and the work you've put out there. I'm new to DevOps and I found TestDriven.io while looking for Django and DevOps related topics. One of the best collections of tutorials and guides I've seen -- very well-written, clear, and concise. You have saved me so much time and energy. Thanks from the bottom of my heart.

I am very much into buying and purchasing any course by you and your team. I've never felt like a better programmer ready to show my coding chops to the world.

Frequently Asked Questions

What tools and technologies are used in this course?

This course covers a variety of technologies and services:

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

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:

https://flask-stock-portfolio-app.herokuapp.com/

Demo:

What support does TestDriven.io offer?

Since the courses mimic real-world development, support is provided via Stack Overflow. Helpful users, including the developers of the courses, read and respond to messages on Stack Overflow. If you get stuck and you can't find an answer via Stack Overflow, feel free to reach out via email directly. Just be sure to detail what you've tried. For more, review Support and Consulting.

How long does it take to complete the course?

It's dependent on your current skill level. On average, it takes approximately 12 hours to complete.