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 = """
<!DOCTYPE html>
<html>
<head>
<title>luksha</title>
</head>
<body>
<center><h2>Laptop config (25014479)</h2>
<table border="">
<tr>
<th>Device name</th>
<th>Storage></th>
<th>Ram</th>
<th>Processor</th>
<th>Graphics card</th>
</tr>
<tr>
<td>lenovo</td>
<td>256 GB</td>
<td>8GB</td>
<td>i3</td>
<td>64GB</td>
</tr>
<tr>
<td>Acer</td>
<td>512GB</td>
<td>32GB</td>
<td>i5</td>
<td>128GB</td>
</tr>
<tr>
<td>Asus</td>
<td>1TB</td>
<td>32GB</td>
<td>AMD ryzan</td>
<td>128GB</td>
</tr>
<tr>
<td>Mac Book</td>
<td>512GB</td>
<td>32GB</td>
<td>i5</td>
<td>128GB</td>
</tr>
<tr>
<td>Google chrome book</td>
<td>256GB</td>
<td>32GB</td>
<td>i3</td>
<td>128GB</td>
</tr>
</table>
</center>
</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.
.png)