#100DaysOfWeb in Python Transcripts
Chapter: Days 1-4: Flask Intro
Lecture: Define your Flask app routes in routes.py

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Alright, welcome back.
0:01 In our last video we looked at the __init__.py file
0:07 and we now move on to the routes.py file.
0:12 You can see the relationship here.
0:14 At the end of __init__.py where we're setting up
0:16 our Flask app instance, the last thing we do
0:20 is we then say, from our program package, import routes
0:25 which is going to be our routes.py file.
0:28 Let's edit that file now
0:30 so we actually have something to import.
0:32 Something to work with.
0:34 Now, traditionally, if this was a single file Flask app
0:39 we would import Flask here
0:41 but we've already done that in the __init__.py file
0:45 so we can pretty much get straight to the code.
0:49 The only thing that we need to import here is the Flask app.
0:54 Okay, that app object that we created in our __init__.py file.
0:59 To do that, we just simply go, from program
1:04 from program import app.
1:08 And the whole __init__.py thing handles that, alright?
1:12 That's all we need for the absolute basic Flask app here
1:16 using our packaged app scenario.
1:19 Alright, so pretty much we can get
1:21 straight into the Flask code.
1:23 What we're going to do here
1:24 is we're going to create an app route.
1:27 Now, this is going to be our URL.
1:30 So the first URL we want to create is the root
1:33 or the index path.
1:36 In this instance, we can actually specify both
1:39 'cause they are practically the same thing, okay?
1:42 So, we have this decorator here
1:45 and it is creating our URL.
1:50 What is it creating that against?
1:51 What is the code that is going to run against this URL?
1:55 That's what the decorator works against.
1:58 In this case, we're going to run it against this function
2:01 and we're going to call the function index().
2:05 General rule of thumb, I wouldn't say all the time
2:07 but one of the good practices with Flask
2:09 is to try and name your functions
2:13 similar to your actual URL.
2:17 So, this is the index() function
2:19 for the index or root path to our website.
2:24 Alright. For the simplest of simple
2:28 all we're going to do is return something
2:31 which is just plain text.
2:32 We're just going to return plain text.
2:36 We go "Hello Pythonistas" and that's it.
2:43 That's all we're returning.
2:44 And would you believe it, that is our app.
2:47 That's all we need to do, to make this very simple
2:52 initial Flash app work. So we can save that
2:57 and we can pretty much run our app now.
2:59 We just have to do one last thing
3:01 so move on to the next video
3:03 we're going to configure that demo.py file
3:05 and you'll see why I've left that 'till the end
3:08 in the next video.