├── .gitattributes ├── README.md ├── index.html ├── serv.py └── test.html /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 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 7 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Hello world! 6 | 7 | 8 |

Index page!

9 | 10 | 11 | -------------------------------------------------------------------------------- /serv.py: -------------------------------------------------------------------------------- 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() 21 | -------------------------------------------------------------------------------- /test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Hello world! 6 | 7 | 8 |

Hello World!

9 | 10 | 11 | --------------------------------------------------------------------------------