To develop a simple webserver to serve html pages and display the Device Specifications of your Laptop.
HTML content creation.
Design of webserver workflow.
Implementation using Python code.
Import the necessary modules.
Define a custom request handler.
Start an HTTP server on a specific port.
Run the Python script to serve web pages.
Serve the HTML pages.
Start the server script and check for errors.
Open a browser and navigate to http://127.0.0.1:8000 (or the assigned port).
from http.server import HTTPServer, BaseHTTPRequestHandler
content = """
<html>
<head>
<title>
</title>
</head>
<body>
<h1 align="center">Device specifications</h1>
<table border="15" width="775" height="490" cellpadding="45" bgcolor="lightpink" align="center">
<tr>
<th bgcolor="lightblue">S.no</th>
<th bgcolor="lightblue">Device specification</th>
<th bgcolor="lightblue">Type</th>
</tr>
<tr>
<td>1</td>
<td>Device name</td>
<td>IJAS LAPTOP</td>
</tr>
<tr>
<td>2</td>
<td>Processor</td>
<td>AMD RYZEN 7 HEXA CORE</td>
</tr>
<tr>
<td>3</td>
<td>RAM</td>
<td>16gb ram</td>
</tr>
<tr>
<td>4</td>
<td>GRAPICS CARD</td>
<td>6GB NVIDIA RTX 4050</td>
</tr>
<tr>
<td>5</td>
<td>KEYBOARD LIGHT</td>
<td>MULTICOLOUR LIGHT</td>
</table>
</body>
</html>
"""
class myhandler(BaseHTTPRequestHandler):
def do_GET(self):
print("request received")
self.send_response(200)
self.send_header('content-type', 'text/html; charset=utf-8')
self.end_headers()
self.wfile.write(content.encode())
server_address = ('',8000)
httpd = HTTPServer(server_address,myhandler)
print("my webserver is running...")
httpd.serve_forever()
The program for implementing simple webserver is executed successfully.