1
00:00:00,870 --> 00:00:07,120
Welcome again. In this lecture you will learn how to generate HTML pages using your Python web

2
00:00:07,130 --> 00:00:07,980
app.

3
00:00:08,040 --> 00:00:13,890
In the previous lecture we simply returned some plain strings as you see here.

4
00:00:13,890 --> 00:00:15,590
So return a string.

5
00:00:15,990 --> 00:00:20,560
Now we will return an HTML template in here and to do that

6
00:00:20,610 --> 00:00:31,490
we need to use the render template method of the flask library and what render template does is accesses

7
00:00:31,740 --> 00:00:39,870
An HTML file stored somewhere in our Python application, in our python files and that displays that HTML

8
00:00:39,870 --> 00:00:42,200
of the requested URL.

9
00:00:42,560 --> 00:00:49,750
So we need to replace this with full name of an HTML page.

10
00:00:49,920 --> 00:00:51,050
Let's say home.html.

11
00:00:51,120 --> 00:00:54,020
And this name here,

12
00:00:54,030 --> 00:01:03,270
this file name it has to reflect a real HTML file which has to be stored in a folder which itself has to

13
00:01:03,270 --> 00:01:11,850
be name templates so be sure you use this names so when you create a folder inside the folder then

14
00:01:11,850 --> 00:01:19,290
you need to create an HTML file. Home.html and the name has to reflect the name you're returning

15
00:01:19,290 --> 00:01:19,830
here.

16
00:01:19,890 --> 00:01:22,270
In the render template method.

17
00:01:22,530 --> 00:01:23,550
That's it.

18
00:01:23,700 --> 00:01:26,050
And here is where your ID HTML code is now.

19
00:01:26,060 --> 00:01:28,770
If you know HTML already

20
00:01:28,770 --> 00:01:31,650
this should be as easy as breathing.

21
00:01:32,250 --> 00:01:34,720
If you don't know that it should be easy to learn.

22
00:01:34,860 --> 00:01:39,980
If you know a bit of Python now which you should, learning HTML is just a breeze.

23
00:01:39,990 --> 00:01:42,150
So just go there and learn

24
00:01:42,150 --> 00:01:43,320
Some HTML.

25
00:01:43,510 --> 00:01:45,810
It's that easy.

26
00:01:45,900 --> 00:01:49,220
Anyway I'll create an HTML file here.

27
00:01:49,650 --> 00:01:53,710
Everything starts with a declaration of document type.

28
00:01:53,820 --> 00:01:55,460
HTML.

29
00:01:56,130 --> 00:02:02,840
Then you have the HTML tags. That was the opening tag and you also have the closing tag.

30
00:02:03,300 --> 00:02:04,190
That's it.

31
00:02:04,470 --> 00:02:05,730
You have body tags.

32
00:02:12,540 --> 00:02:13,400
Just like that.

33
00:02:13,550 --> 00:02:17,080
And so here goes the content of your web page.

34
00:02:17,120 --> 00:02:20,580
So let's say I want a heading like this

35
00:02:23,310 --> 00:02:25,850
and inside here you can put some text.

36
00:02:26,310 --> 00:02:29,080
My home page for example.

37
00:02:29,940 --> 00:02:33,600
And yet another different type of tag which is a paragraph tag.

38
00:02:36,300 --> 00:02:39,890
And say this is a test website.

39
00:02:39,990 --> 00:02:43,500
Click save and yeah, you should be good to go.

40
00:02:43,500 --> 00:02:50,640
Go to your script make sure you have saved it and the web app is starting and I'll go now and visit my home

41
00:02:50,640 --> 00:02:51,960
page.

42
00:02:51,990 --> 00:02:53,980
This is the about page.

43
00:02:53,980 --> 00:02:57,100
This should be the home page.

44
00:02:57,270 --> 00:03:00,650
Yeah, I seem to have a little typo in here I guess.

45
00:03:00,650 --> 00:03:05,190
Yeah, this should be h1 as the opening tag.

46
00:03:05,370 --> 00:03:07,180
Click save and you don't have to rerun

47
00:03:07,180 --> 00:03:10,020
The Python script.

48
00:03:10,230 --> 00:03:12,490
Just go here reload the page.

49
00:03:13,020 --> 00:03:16,630
Now this is a normal text now so this is a paragraph.

50
00:03:16,950 --> 00:03:21,000
This is a heading. I think great, so.

51
00:03:21,820 --> 00:03:27,750
We can also have another page for the about page if you want to just quickly duplicate this.

52
00:03:27,750 --> 00:03:32,220
Say about my about page here.

53
00:03:32,220 --> 00:03:42,210
This is a test website. Again just like that you go to your script one and change this to render template.

54
00:03:42,210 --> 00:03:42,510

55
00:03:42,510 --> 00:03:52,140
and then you pass a about.html. Click save, go to the local host. This should be the home page.

56
00:03:52,140 --> 00:03:54,980
You have about the page.

57
00:03:55,300 --> 00:03:58,090
Yeah, my about page. This is the website again.

58
00:03:58,410 --> 00:03:59,220
So that's it.

59
00:03:59,280 --> 00:04:04,060
That's how you pass HTML templates to your Python web app.

60
00:04:04,110 --> 00:04:07,090
And that is how you map them to your HTMLs.

61
00:04:07,200 --> 00:04:09,400
Let's move on to the next lecture.

