In this short video, you will learn how to create and publish a website on the web.
For this, you're going to need to repl.
Of course, you can make the website in your local IDE, but to publish it you need repl,
so replit.com.
I showed you previously how to use repl.
So basically what we do is we create a new repl.
Choose Python as the programming language.
Give a name to the repl.
Publish a website in two minutes.
The name can be anything.
And then in this main.py file, you want to write the webapp, so the website. To create a website,
you need a web framework and Flask is one of the frameworks for Python.
You also have Django. Flask is easier to make websites.
So we're going to use Flask. From flask
you import the Flask class.
So that is a class that is part of the flask library.
Now, this flask Library is a third-party library.
But repl will install it automatically when we run the script, so it will install flask.
Then you want to create an object instance using that flask class. As input,
this gets a string, but a good practice is to just put this underscore, underscore, name,
underscore, underscore.
This is a special variable that contains a string as value. The string is the name of this file.
And then, you use a decorator pointing to that variable.
So @app.route and here you define the URL. When the visitor visits the home page.
So this is a home page if you want to handle other pages, for example, book,
you'd want to write the other URL here.
So we have one decorator for each
URL in our website.
So let's start with the home page.
After that decorator, you create a function define home, return
"Welcome to my website".
So that is the function.
Now we want to point to app again and call the run method of that app instance.
So app is created from Flask,
this class, and this class has this run method.
So therefore, we can access that around methods through the app instance.
Since this is an instance of Flask. Now on repl, you have to specify a hosts, which should be 0.0.0.0.
Repl will listen for websites that are running in this IP address, this local internal IP address
and then repl what it will do is it will create a URL, a public URL for your website.
So see what happens if I run this now?
First, repl will install flask and other dependencies.
And then, this browser will open up, so it's a browser embedded in repl, and this is the website, so that's
"Welcome to my website".
That's the content of our website.
If you get this URL and you just put it in your browser,
you will see the website, so everyone can visit your website now given that URL.
And that's how you create a website in just about two minutes.
Know that if you were running this locally, you have to take care of the publishing parts.
So you may want to use another service such as Digital Ocean or Pythonanywhere to publish your websites.
But the process is more manual, so you have to upload your website there.
But in this case, in repl, you just write the code here, you run it and you can just close this repl now.
You close it and the website is still live.
Now, this was a very simple website.
You saw that we used a plain python string to write the content of the website.
In reality, you want to use the HTML because in the HTML, you can also put pictures and you can stylize
the text with headings and other font styles.
In the course, we do have a lecture on creating web apps with flask.
So just search in the course overview for the flask keyword in your browser and you will find that the
lecture "Creating web apps with flask".
So that's about this video.
Thank you, and I'll talk to you later.