Welcome again! In this lecture, you'll
learn how to generate HTML pages using
your Python web app. In the previous
lecture, we simply return some plain
strings, as you see here, so return a
string. Now we will return an HTML
template in here. And to do that, we need to
use the render_template method of the
flask library. And what render_template
does is accesses an HTML file stored
somewhere in our Python application,
in our Python files, and then displays
that HTML all the requested URL. So we need
to replace this with name of the
HTML page, let's say home.html, and
this name here, this file name has to
reflect a real HTML file, which has to
be stored in a folder, which itself has
to be named templates. So be sure you
use this names when you create a
folder. Inside the folder, then you need
to create an HTML file, home.html.
And the name has to reflect the name
you're returning here in the render_template method.
That's it. And here is
where you write the HTML code now. If
you know HTML already, this should be as
easy as breathing. If you don't know
then it should be easy to learn. If you
know a bit of Python now, which you
should, learning HTML is just a breeze.
So just go ahead there and learn some
HTML. It's that easy. But anyway, I'll
create an HTML file here. Everything
starts with a declaration of the
DOCUMENTTYPE html. Then you have the
HTML tags. That was a opening tag, and
you also have a closing tag. That's it,
you have body tags.
[Author typing]
Just like that, and inside here goes the
content of your webpage. So let's
say I want a heading like this.
[No audio]
And inside here you can put some tags,
My homepage, for example.
And yet another different
type of tag, which is a paragraph tag.
[No audio]
And say, This is a test website, click
Save, and yeah, you should be good to go,
go to your script, make sure you have
saved it, and the web app is restarting, and
I'll go now and visit My homepage. This
is the About page. This should be the
homepage. I seem to have a
little typo in here, I guess. Yeah, this
should be h1 as the opening tag,
click Save, and you don't have to re-run
the Python script, just go here,
reload the page, and this is normal text,
now. So this is a paragraph, and this is
heading. Great. So we can also have
another page for the About page. If you
want just quickly Duplicate this, say
about, My about page, here, This is a test
website again, just like that, you go
to your script1 and change this to
render_template and then you pass about.html
click Save, go to the localhost.
This should be the homepage. You have
the about page. Yeah, My about page. So
this is test website again. So that's
it. That's how you pass HTML templates
to your Python web app, and that's how
you map them to your URLs. Let's move on
then to the next lecture.