Hi Everyone, Today I will show you how to host your files with your own web server in python.

Step 1: Install The Dependencies

First, Install the dependencies.

pip install flask

Or

pip3 install flask

Step 2: Make index.html

Create index.html with the following code. Place index.html in a directory called templates.

<!DOCTYPE html>
<html>
<head>
<style>
.works {
color: green;
}
</style>
<title>
Test page
</title>
</head>
<body>
<h1 class="works">Your code works!</h1>
</body>
</html>

You should get the output (Picture given below)

Step 3: Writing the python code

First, Import Flask and the render_template function. Then write the real code.

from flask import Flask, render_template

app = Flask(__name__)

@app.route('/') 
def index():     
  return render_template('index.html')

if __name__ == '__main__':     
  app.run(debug=True, host='0.0.0.0')

Copy the @app.route function with define index() and return for every file you host.

Now save the file as app.py outside the templates directory that you created earlier. Now Run your code. Wait Till you get the output Debugger is active

Then visit http://localhost:5000 and see your html page pop up!

Now you can stop running the file. Remember to have the python file running when you want to visit the files.

Thats it!