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