Skip to content

Commit f665259

Browse files
committed
Added source code
Added source code
1 parent eb13c67 commit f665259

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Simple Python Web Server
2+
========================
3+
4+
This is the source code for howCode's simple Python Web Server.
5+
6+
You can watch the video that accompanies this source code here: https://youtu.be/hFNZ6kdBgO0

index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Hello world!</title>
6+
</head>
7+
<body>
8+
<h1>Index page!</h1>
9+
</body>
10+
</html>

serv.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from http.server import HTTPServer, BaseHTTPRequestHandler
2+
3+
4+
class Serv(BaseHTTPRequestHandler):
5+
6+
def do_GET(self):
7+
if self.path == '/':
8+
self.path = '/index.html'
9+
try:
10+
file_to_open = open(self.path[1:]).read()
11+
self.send_response(200)
12+
except:
13+
file_to_open = "File not found"
14+
self.send_response(404)
15+
self.end_headers()
16+
self.wfile.write(bytes(file_to_open, 'utf-8'))
17+
18+
19+
httpd = HTTPServer(('localhost', 8080), Serv)
20+
httpd.serve_forever()

test.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Hello world!</title>
6+
</head>
7+
<body>
8+
<h1>Hello World!</h1>
9+
</body>
10+
</html>

0 commit comments

Comments
 (0)