-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
30 lines (24 loc) · 757 Bytes
/
main.py
File metadata and controls
30 lines (24 loc) · 757 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from http.server import BaseHTTPRequestHandler, HTTPServer
import pyjokes
class MyHandler(BaseHTTPRequestHandler):
def do_GET(self):
joke = pyjokes.get_joke()
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
html_content = f"""
<html>
<head>
<title>Welcome to My Joke Page :)</title>
</head>
<body>
<h1>main page</h1>
<p>Time for a quick joke:</p>
<blockquote>{joke}</blockquote>
</body>
</html>
"""
self.wfile.write(html_content.encode('utf-8'))
if __name__ == "__main__":
server = HTTPServer(('0.0.0.0', 8000), MyHandler)
server.serve_forever()