Class Central is learner-supported. When you buy through links on our site, we may earn an affiliate commission.

Treehouse

A Social Network with Flask Course (How To)

via Treehouse

Overview

It's time to dig in and build something big. In this course, we're going to take the tools we've learned, Flask, Peewee, and Python itself, and build a small social network. We'll have user registration, user authentication, strongly hashed passwords, form validation, and more.

What you'll learn

  • User registration and authentication
  • Password hashing
  • Form validation
  • Joins

Syllabus

Making Strong Users

We won't get far in our social application with out users. Let's make sure their passwords are stored correctly and strongly, too.

Chevron 10 steps
  • Our Project

    1:38

  • Flask and Peewee Review

    6 questions

  • The User Model

    4:57

  • Create a User model

    3 objectives

  • The UserMixin From Flask-Login

    5:50

  • Add UserMixin

    2 objectives

  • Cryptographic Hashing with Flask-Bcrypt

    6:50

  • Bcryptkeeper

    3 objectives

  • Class Method

    4:07

  • What's a method like you doing in a class like this?

    2 objectives

Takin' Names

Users need a way to sign up and sign in to our site. We'll need to validate their information, create our model instances, and store their session information. Luckily, we have a few handy libraries to do a lot of that for us!

Chevron 12 steps
  • Before and After Requests

    4:27

  • To the ends of the request

    3 objectives

  • LoginManager

    4:38

  • Set up LoginManager

    4 objectives

  • Flask-WTF Forms

    9:39

  • Form with Validators

    4 objectives

  • Registration View

    6:33

  • Macros

    4:19

  • Login View

    6:17

  • Form View

    3 objectives

  • Logout View

    3:24

  • Controlling sessions

    2 objectives

Broadcasting

Our app needs messages posted by the users. Let's give them a model, a form, and the views necessary so they can tell the world what they're up to.

Chevron 10 steps
  • Add Some Layout

    7:01

  • Add current_user Check

    2 objectives

  • Post Model

    4:05

  • Lunch Order Model

    3 objectives

  • Post Form and View

    7:14

  • Lunch Order Form

    3 objectives

  • Stream Views

    7:21

  • Lunch order view

    1 objective

  • Stream Templates

    6:27

  • Lunch Template

    2 objectives

How to Win Friends

The final ingredient in any social site is the ability to follow people. We'll need to add a new model, a couple of views, and tweak a template or two. We'll also want to change a query or two to get the full social experience.

Chevron 10 steps
  • Relationship Model

    5:36

  • Related Users

    4 objectives

  • Follow and Unfollow Buttons

    8:06

  • Follow/Unfollow views

    2 objectives

  • Show Follower Posts

    4:21

  • Lunch Count

    1 objective

  • Handling 404s

    5:40

  • Uh-Oh 404!

    3 objectives

  • Suggestions

    0:43

  • Review: Build a Social Network with Flask

    6 questions

  • Extra Credit

    Some other ideas for extending this app are:

    • Add a form and view to allow users to change their username, email address, and password.
    • Allow users to repost or respond to updates in a linked method. You'd probably want to start by adding a foreign key to Post that pointed to another Post.

Reviews

Start your review of A Social Network with Flask Course (How To)

Never Stop Learning.

Get personalized course recommendations, track subjects and courses with reminders, and more.

Someone learning on their laptop while sitting on the floor.