web server python code example

Example 1: python start simplehttpserver

# If Python version is 3.X
python3 -m http.server

# If Python version is 2.X
python -m SimpleHTTPServer

Example 2: python httpserver

python -m http.server 8000 --bind 127.0.0.1

Example 3: python3 webserver command line

python3 -m http.server

Example 4: web server python

# Creating a Web server using Python and Flask

from flask import Flask

app = Flask('app')
@app.route('/')

def run():
    return '<h1>Hello, Server!</h1>'

app.run(host = '0.0.0.0', port = 8080)

Example 5: http.server python

python -m http.server 8000

Example 6: how does HTTPServer work in python

def run(server_class=HTTPServer, handler_class=S, addr="localhost", port=8000):

    server_address = (addr, port)               
    httpd = server_class(server_address, handler_class) 
    httpd.serve_forever()