Last active
January 1, 2021 07:14
-
-
Save guangrei/94f23c5effd71f91a7cef1ceabfc6388 to your computer and use it in GitHub Desktop.
python web tanpa framework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from http.server import BaseHTTPRequestHandler | |
from urllib import parse | |
from http.server import HTTPServer | |
class GetHandler(BaseHTTPRequestHandler): | |
def do_GET(self): | |
parsed_path = parse.urlparse(self.path) | |
res = """ | |
<html><head><title>hello from shin</title> | |
</head><body> | |
fb <a href="https://fb.me/shiin.kun2">shin</a> | |
</body> | |
</html> | |
""" | |
self.send_response(200) | |
self.send_header('Content-Type', | |
'text/html; charset=utf-8') | |
self.end_headers() | |
self.wfile.write(res.encode("utf-8")) | |
if __name__ == '__main__': | |
server = HTTPServer(('localhost', 8081), GetHandler) | |
print('Starting server, use <Ctrl-C> to stop') | |
server.serve_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment