1
00:00:00,060 --> 00:00:06,090
In this short video, you will learn how to create and publish a website on the web.

2
00:00:06,630 --> 00:00:08,520
For this, you're going to need to repl.

3
00:00:09,150 --> 00:00:15,660
Of course, you can make the website in your local IDE, but to publish it you need repl, 

4
00:00:15,660 --> 00:00:16,410
so replit.com.

5
00:00:16,710 --> 00:00:18,840
I showed you previously how to use repl.

6
00:00:18,930 --> 00:00:21,540
So basically what we do is we create a new repl.

7
00:00:21,990 --> 00:00:24,540
Choose Python as the programming language.

8
00:00:24,960 --> 00:00:26,370
Give a name to the repl.

9
00:00:28,200 --> 00:00:32,130
Publish a website in two minutes.

10
00:00:33,150 --> 00:00:34,380
The name can be anything.

11
00:00:38,950 --> 00:00:47,170
And then in this main.py file, you want to write the webapp, so the website. To create a website,

12
00:00:47,210 --> 00:00:54,000
you need a web framework and Flask is one of the frameworks for Python.

13
00:00:54,030 --> 00:00:57,660
You also have Django. Flask is easier to make websites.

14
00:00:58,830 --> 00:01:02,460
So we're going to use Flask. From flask

15
00:01:02,640 --> 00:01:04,470
you import the Flask class.

16
00:01:04,800 --> 00:01:08,220
So that is a class that is part of the flask library.

17
00:01:09,990 --> 00:01:12,930
Now, this flask Library is a third-party library.

18
00:01:13,080 --> 00:01:19,140
But repl will install it automatically when we run the script, so it will install flask.

19
00:01:19,620 --> 00:01:27,880
Then you want to create an object instance using that flask class. As input,

20
00:01:27,930 --> 00:01:33,990
this gets a string, but a good practice is to just put this underscore, underscore, name,

21
00:01:33,990 --> 00:01:35,220
underscore, underscore.

22
00:01:35,490 --> 00:01:42,630
This is a special variable that contains a string as value. The string is the name of this file.

23
00:01:44,290 --> 00:01:47,590
And then, you use a decorator pointing to that variable.

24
00:01:49,250 --> 00:01:59,010
So @app.route and here you define the URL. When the visitor visits the home page.

25
00:01:59,030 --> 00:02:07,090
So this is a home page if you want to handle other pages, for example, book,

26
00:02:07,970 --> 00:02:10,130
you'd want to write the other URL here.

27
00:02:10,280 --> 00:02:13,100
So we have one decorator for each

28
00:02:13,100 --> 00:02:14,380
URL in our website.

29
00:02:14,780 --> 00:02:16,580
So let's start with the home page.

30
00:02:17,810 --> 00:02:23,450
After that decorator, you create a function define home, return

31
00:02:24,500 --> 00:02:27,170
"Welcome to my website".

32
00:02:28,100 --> 00:02:29,230
So that is the function.

33
00:02:29,240 --> 00:02:35,510
Now we want to point to app again and call the run method of that app instance.

34
00:02:35,750 --> 00:02:38,630
So app is created from Flask,

35
00:02:38,960 --> 00:02:41,870
this class, and this class has this run method.

36
00:02:42,140 --> 00:02:46,700
So therefore, we can access that around methods through the app instance.

37
00:02:46,700 --> 00:02:58,070
Since this is an instance of Flask. Now on repl, you have to specify a hosts, which should be 0.0.0.0.

38
00:02:58,940 --> 00:03:07,070
Repl will listen for websites that are running in this IP address, this local internal IP address

39
00:03:07,280 --> 00:03:13,700
and then repl what it will do is it will create a URL, a public URL for your website.

40
00:03:14,000 --> 00:03:16,040
So see what happens if I run this now?

41
00:03:17,280 --> 00:03:21,510
First, repl will install flask and other dependencies.

42
00:03:26,820 --> 00:03:34,790
And then, this browser will open up, so it's a browser embedded in repl, and this is the website, so that's

43
00:03:34,810 --> 00:03:36,240
"Welcome to my website".

44
00:03:36,250 --> 00:03:38,010
That's the content of our website.

45
00:03:38,190 --> 00:03:41,280
If you get this URL and you just put it in your browser,

46
00:03:43,880 --> 00:03:50,540
you will see the website, so everyone can visit your website now given that URL.

47
00:03:52,680 --> 00:03:56,140
And that's how you create a website in just about two minutes.

48
00:03:56,520 --> 00:04:03,400
Know that if you were running this locally, you have to take care of the publishing parts.

49
00:04:03,480 --> 00:04:10,980
So you may want to use another service such as Digital Ocean or Pythonanywhere to publish your websites.

50
00:04:11,220 --> 00:04:15,270
But the process is more manual, so you have to upload your website there.

51
00:04:15,420 --> 00:04:22,290
But in this case, in repl, you just write the code here, you run it and you can just close this repl now.

52
00:04:22,740 --> 00:04:25,410
You close it and the website is still live.

53
00:04:26,400 --> 00:04:28,290
Now, this was a very simple website.

54
00:04:28,530 --> 00:04:34,140
You saw that we used a plain python string to write the content of the website.

55
00:04:34,410 --> 00:04:41,580
In reality, you want to use the HTML because in the HTML, you can also put pictures and you can stylize

56
00:04:41,580 --> 00:04:45,900
the text with headings and other font styles.

57
00:04:46,480 --> 00:04:51,990
In the course, we do have a lecture on creating web apps with flask.

58
00:04:52,200 --> 00:04:58,740
So just search in the course overview for the flask keyword in your browser and you will find that the

59
00:04:58,740 --> 00:05:01,170
lecture "Creating web apps with flask".

60
00:05:01,800 --> 00:05:03,300
So that's about this video.

61
00:05:03,330 --> 00:05:04,650
Thank you, and I'll talk to you later.

