Welcome back.
So we have our well, frankly, really boring website, but we've created our server.
But what else can we do?
A server usually accepts a request from the browser.
Right.
Now, up until now, we've done what we call a route.
Route that is the home route, because in here we haven't written anything.
But sometimes in a website you might see something like blog, right?
And if I hit enter, you see that in that found that URL was not found on the server.
Again.
That's because right now our server is only waiting to hear.
For their route request.
But if we type something like blog, well, there's no function here that cares about that.
So it sees that there's nothing to care about and moves on.
So let's create a blog route as well.
I'm going to copy and paste and just say that, hey, we want to listen to the blog endpoint.
This is going to be called let's call it blog and say these are my thoughts on blogs.
If I save again, we have the debugger mode so I don't need to restart FY refresh.
Now look at that.
These are my thoughts on blogs and if I go to the root directory I get hello.
We now have multiple routes.
How cool is that by the way, if we open up the developer tools?
Go to developer tools.
Open up the network and just refresh your.
You see that we're getting a document ignored this part.
This is just the developer tools and the plugins that I have.
But this is what we get back.
We just get a simple document, a response, which is a text.
And if I go to headers and I actually scroll down.
You see that I requested this URL.
I got a status of 200.
And I see here that the content type that the server responded with was something called text HTML.
Now, this is something that Flask does for us.
You see over here that I just sent a string, but the flask automatically converts that to HTML so that
the browser can understand it.
As a matter of fact, if I go to elements here.
You see here that I have my HTML with a body of helo inside of it.
So that's something that we get automatically, which is really, really nice.
But now we can start doing some really neat things.
For example, let's create another route.
And this time.
Let's say I want the blog from, let's say, 2020 about dogs.
Can I do that?
Well, yeah, absolutely.
Let's say blog to.
And this says, this is my dog.
Very, very engaging blog posts there.
So now if I go back, I do blog.
All right.
I get that.
If I do blog 2020, let's say dogs.
I get this is my dog.
Awesome.
So I can have multiple routes like this.
What if I remove this and have two blocks with the same endpoint?
If we go back.
And just go to blog.
I get these are my thoughts on blogs because once it hits a root that it sees which online nine it sees,
it's going to automatically just return and forget about the rest.
So let's bring our dog's blog post back.
But you know what's a shame?
Because we have this beautiful website.
I'm being sarcastic here, this beautiful HTML website that we've created with CSS and JavaScript.
Wouldn't it be nice if instead of me just sending out text, I can actually send those?
Could I do that?
Well, yeah, you can.
You see, Flask has another thing called.
Render underscore template.
And this render template function is going to allow us to actually send the HTML file.
So let's say the home root now instead of hello is going to do something different.
Instead it's going to run the render template function that comes with flask.
And in here we give it the HTML file that we have so we can give it a root in our case.
Because it's in the same folder as the server file.
We can just do index dot html.
If I run this, let's see if this works.
If I go back to my home route.
Hmm.
Now get in there.
Let's read the air.
Template not found index dot ish html.
Hmm.
So it tried to look for indexed HTML and it didn't find it.
That's not good, is it?
What if we do a dot slash, which means current directory?
Grab the index, html fi, save and refresh.
I still get the air.
Again, this is another thing that you'd have to just learn as you read the documentation.
But the reason that this is not working is because flask automatically, when you say render template
tries to look in a folder called templates.
So let's create that, I'm going to say.
New folder.
Call it templates and put all my HTML files.
In this case, the single HTML file that I have.
I'm going to say move and put it in the templates folder.
So now it's in here.
And let's save.
Go back and refresh.
And look at that.
I am a web master.
Everything is working.
If I go to blog.
Again, these are my thoughts on blogs, but my HTML file that I've created is working perfectly.
How awesome is that?
And Flask uses this idea of templates to add multiple HTML files.
So, for example, I can create a new file.
Let's just say duplicate here.
So I'm going to duplicate this file.
And call it about HML.
And this about HTML is going to say about me.
And let's go into server dot pie and have the root folder at index html and perhaps.
Add another root say about HTML and yes, I can do that as well.
And in here we'll grab the about HTML.
Let's call it whatever we want.
Let's say about function.
And if I go back.
Go to.
About.
Well, it's not going to work, because remember, I added the HTML.
There you go.
About me.
Awesome.
This is great.
We're starting to learn about different routes and how servers work and we're able to send our HTML
file.
But what about the JavaScript files and the CSS files?
How can we do that?
In the next video we'll find out.