#100DaysOfWeb in Python Transcripts
Chapter: Days 57-60: Flask Login
Lecture: Setup: A Barebones Flask app
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
Alright, now I'm going to skip over the things that we sort of covered in the previous Flask sections of the course. I won't go into too much detail
0:11
but for now what we're going to do is we're going to create the launch.py file that I referenced in our Flask env doc file
0:21
so just vim launched.py this will actually be the script that launches our app. And we do that going from project awesome import app and that's it.
0:34
Not u w q right there there we have our file. Now if we go into project awesome we need to create our init.py file. Now this is the script
0:46
that contains the details of our Flask app instance and anything else that needs to be imported. So let's quickly create that now.
0:56
this is everything needed to initialize. So init.py. And if you're looking at the repo for this chapter
1:07
you're going to see there's quite a lot more in this file then you see me writing now. And that's because
1:13
we're going to add to it as we get to those sections. So don't be alarmed if you only see a little bit here. So from flask import flask
1:24
and we can then go app equals flask name, double underscore name. The only other thing we want regarding this app
1:36
is the ability to import our Flask script to the file that's going to contain all of our routes and all of that config.
1:45
Now we called it something else in the other app. This app we're actually going to call it project pause, import. We're just going to call it routes.
1:55
I thought we'd keep it simple. Just it's got all the routes in it. So we'll call it routes. So from project awesome import routes.
2:05
Now let's create that routes file. And same thing. This is going to look really bare bones compared to what you see in the repo. So just roll with it.
2:16
Let's create the absolute base app the framework that we're going to build on for the rest of this. So to do that
2:24
we just need to import a couple of things, not everything. So let's import everything we need from Flask to be able to render some templates.
2:35
So from flask, import, render_template. And we'll leave it there actually. We'll leave it there for now. Nice and simple.
2:48
Next, we need to import our Flask app instance. Okay, and we use the same thing we use the other file. So from project awesome import app.
3:01
Now again, if you're looking at the repo there's a lot more there don't worry about it, we'll get to it. That's all we need to build the base app.
3:09
And the very first page that we're going to deal with here in our app, the first web page is the Index page. So we need to create an index route.
3:19
And as per the other apps that we've made to date we're just going to create two app route decorators here to cover the different
3:29
URLs that this will cover. All right, so route and index. And we're going to go index return render_template. And as with the other apps
3:47
let's call our template exactly what it is and that it is index dot HTML. All right, that's pretty much all we're going to create now
3:56
because any of the other pages they're going to start touching on some of the more complex stuff. So the last thing we need here is and pass.
4:08
Let's just throw that in. And that's all we're going to have here. All right, let's hop into our templates directory.
4:17
And we're going to quickly throw in the code for index.html. Now, you will notice that all of these files that I'm creating, all of these templates
4:29
that I'm creating are going to be really, really, really basic. I'm going to have little to no CSS in there. They're going to look really old
4:40
with the lack of styling. So we'll start this file off with the HTML tag. We're throw in the head tag
4:48
throw in a title, and we'll just call it homepage. That's it. Close off the head. And then we'll trow in a body tag, h1.
5:11
This, now this is very specific text because I want to make sure that we know when we're going to be on this page in a logged in and logged out view.
5:19
So obviously, anyone who accesses your page from the very beginning is going to be logged out. Okay, so we're going to demonstrate that here.
5:28
So this is the homepage. You do not need to be logged in to access this page. So anyone who hits this page can actually access it.
5:43
Then we throw in the clothed body tag and we close in some HTML. Oops. All right, now that we have that
5:57
we can actually just quickly demonstrate that the app works. And on port 5000 of local hosts one two seven dot zero dot zero dot one.
6:11
You can see that we have, this is the homepage you do not need to be logged in to access this page. So that's all we need to do in this specific video.
6:19
We know we have an barebones app that