Intermediate Python

Flask Practice Setup

Intermediate Python

Check out a free preview of the full Intermediate Python course

The "Flask Practice Setup" Lesson is part of the full, Intermediate Python course featured in this preview video. Here's what you'd learn in this lesson:

Nina prepares the audience to go through the last exercise of the course.


Transcript from the "Flask Practice Setup" Lesson

>> Nina Zakharenko: And all of that leads us into our final exercise. So for intermediate Python, go to Chapter eight, the final exercise. We're going to build that basic web app that we saw earlier. And let me kill this one and bring up the window where I had it running.

>> Nina Zakharenko: So this basic web app, sorry,
>> Nina Zakharenko: Allows us to select our languages via checkbox and hit Submit, and with each submission, we don't have a database, we're just hitting the GitHub API. So for the few of you folks in class, as you build this, if you kinda really mash all the buttons, you might hit the rate limit, so just something to be mindful of.

And I can go and hit this API filter by whichever language I want.
>> Nina Zakharenko: Okay, for this exercise, if you go to the class website, you should have flask and requests installed already. If you don't, you can take a look at this requirements.txt file that I put in with my package.

And this file is in the course repository, so if you get poll, you'll get all the latest changes. This lists all of the libraries that are required to run my program. You can even peg these to a specific version with a double equal signs if you want to, just an example there.

So if you didn't have the required dependencies installed, you can do a python -m pip install and then pass the -r flag to specify a file. Once you advance in your Python journey and your requirements become more complicated, you can use the more advanced pipenv tool to handle complicated dependencies.

So just an important thing about this final exercise. Download the zip file that contains the static files for this application. And just like the templates directory, where Flask just knew all my templates just lived in there. For our static files, we have a static directory, and Flask just knows that those are static files.

So I'm going to provide you with a CSS file and an index.html template that does the ginger templating for you. And you're gonna write your own flask routing that takes, the route is gonna be at the root URL, or that route is gonna accept a get and a post, right, when we submit a form, that's gonna be an HTTP post.

When we first visit the page that's just a get, and you're gonna build that along with the static files that I provide. You're also gonna use some of the things that we learned earlier. So, our GitHub repositories, those are gonna be stored in our own class. We're gonna throw a custom exception.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now