Dec-09-2020, 04:24 PM
(This post was last modified: Dec-09-2020, 04:59 PM by swisscheese.)
# This is a simple python web server which displays a button and “Hello”.
# How can I modify the code so that when I click the button the webpage shows the word “There”?
# I need the button to make a request to the server which will then serve the HTML with the change.
# I’ve been searching for days for an answer to this.
# My project does more than this but this is all I need to move forward.
# How can I modify the code so that when I click the button the webpage shows the word “There”?
# I need the button to make a request to the server which will then serve the HTML with the change.
# I’ve been searching for days for an answer to this.
# My project does more than this but this is all I need to move forward.
from http.server import BaseHTTPRequestHandler, HTTPServer
Template = """<!DOCTYPE html><html><head><meta name="viewport" content="width=device-width, initial-scale=1"></head><body>Hello <button class="button">Click</button></body></html>"""
class MyServer(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
self.wfile.write(bytes(Template, "utf-8"))
if __name__ == "__main__":
webServer = HTTPServer(("localhost",80), MyServer)
print("Server started http://%s:%s" % (hostName, serverPort))
try: webServer.serve_forever()
except KeyboardInterrupt: pass
webServer.server_close()
print("Server stopped.")
