Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python serve html

# Python 3 server example
from http.server import BaseHTTPRequestHandler, HTTPServer
import time

hostName = "localhost"
serverPort = 8080

class MyServer(BaseHTTPRequestHandler):
    def do_GET(self):
        self.send_response(200)
        self.send_header("Content-type", "text/html")
        self.end_headers()
        self.wfile.write(bytes("<html><head><title>https://pythonbasics.org</title></head>", "utf-8"))
        self.wfile.write(bytes("<p>Request: %s</p>" % self.path, "utf-8"))
        self.wfile.write(bytes("<body>", "utf-8"))
        self.wfile.write(bytes("<p>This is an example web server.</p>", "utf-8"))
        self.wfile.write(bytes("</body></html>", "utf-8"))

if __name__ == "__main__":        
    webServer = HTTPServer((hostName, serverPort), MyServer)
    print("Server started http://%s:%s" % (hostName, serverPort))

    try:
        webServer.serve_forever()
    except KeyboardInterrupt:
        pass

    webServer.server_close()
    print("Server stopped.")
https://mefiz.com/  # For Developer
#code reference
#https://pythonbasics.org/webserver/
Comment

PREVIOUS NEXT
Code Example
Python :: Is python statically typed language? 
Python :: django fixtures. To loaddata 
Python :: convert price to float pandas 
Python :: python type annotations list of specific values 
Python :: python install graphviz and 
Python :: sets in python 
Python :: remove all parentheses from string python 
Python :: install python ubuntu 
Python :: filter lambda python 
Python :: To Divide or Not To Divide codechef solution 
Python :: py how to replace a string in a list 
Python :: tkinter python button 
Python :: add item to tuple 
Python :: Python program to print positive numbers in a list 
Python :: scan python 
Python :: python destructure object 
Python :: objects.filter django 
Python :: ord() in python 
Python :: django httpresponse 
Python :: how to run python in atom 
Python :: journalctl not showing all python prints 
Python :: pandas series add word to every item in series 
Python :: max element in dictionary python 
Python :: python eliptic curve matplotlib 
Python :: chrome detach selenium python 
Python :: how to add items to tuple in python 
Python :: pyhton dms to decimal 
Python :: python post request binary file 
Python :: python unicode function 
Python :: append two dfs 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =