Welcome back.
A flask has this other tool called variable rules that we haven't talked about.
And what variable rules allows us to do is to do something like this dynamic.
So, for example, slash user slash with these greater than and less than signs and the username.
Now.
We'll get back to this in a second and some of this syntax.
But if we go back.
What we can do here in our server pie.
It's perhaps let's remove this because we don't need it anymore inside of our hello world.
Let's say that we want a name in here.
Or in our case, username.
Now, the neat thing is that Flask is going to look at this and say, oh, this.
It's something that we can pass on into this function.
So I can now say username equals.
The username that we receive.
So let's say username and let's just change this to name just so you see what the differences are.
So I'm placing whatever I receive here into the hello world name parameter and now in my index html.
I can pass on this data by simply doing a second parameter and saying name equals to name.
So now if I save this, go back to my index HTML and put in name in here.
And if I go back to our home page.
If we go to our home page.
And I made a little mistake here.
This should be over here.
So it's saying username from up here is going to equal a default if we want.
So it's usually a good idea to have a default.
I'll just do none for now.
So that username now is going to be.
Username in here.
Like this if I save.
Go back, I get a not found because we don't have a home page anymore.
But any time I do, let's say, Andre, I get look of that Andre on my page, I get Bob and my good
friend Sally.
How cool is that?
So it's able to read the URL and pass in data this way.
And if we go to our flask documentation and we go to variable rules, you see that we have different
rules that we can apply.
For example, we can actually require.
To accept a positive integer or a string or a float.
A path so it accepts slashes or something called you ID, which is kind of like a unique identifier.
So let's try that.
Let's do a post ID here or in our case, let's just copy this and say I also want the user name and
then perhaps accept some sort of a number.
So instead of post ID, maybe it could be, I don't know.
Actually post ID is good.
Let's keep it like that.
And let's make this a little bit bigger.
Now in here.
The second parameter can be the post ID that's going to equal to none to begin with.
And we're also going to pass this.
As post ID that's going to equal.
The post ID if I save this, go to index html and in here let's do a name and then we'll also do the
post ID in here.
If I safe, go back.
And I refresh.
Well, again, because we've made our Earl very specific.
We'll just have to give some sort of a number and look at that.
I have Sally, too.
So that's her second blog post, then the fifth blog post, so on and so forth.
And if I do something, that's not a number.
So if I do some string.
I get not -- because I've made the rule using this syntax.
So int with the colon saying that that this has to be an ID and I passed data down this way.
So now we've created a fallout server.
We now are able to use URLs to communicate with the server and ask for specific data for it to receive
our server based on what URL parameters we give it or end points is able to decide what resource to
send to the front end.
So that it can display the appropriate information.
But we can also do something interesting, like perhaps when we submit a form to actually send perhaps
the user's name with the form, so that when we send back a thank you note, we can say thank you,
Andre, or thank you whatever the username is.
Very, very cool.
Now, these variable rules, as you can see, there's a few of them and you can read through the documentation.
You might also notice this syntax here, which is the percent sign or percent SW or percent DX.
This is actually another.
Feature of Python that you can read about.
But again, it's not critical to your understanding of Python.
For now, though, I think we have the basic skills necessary to start building our portfolio website
because up until now, frankly.
This website doesn't look that great.
So starting in the next video, we're going to build a really, really cool website, something that
looks, well, more like this.
So that by the end of it we can have a fully fledged portfolio website.
And even though it seems like you haven't learned that much yet, you actually have learned all the
skills necessary to build something like this.
Well, kind of.
Let's go explore some more in the next video.