There is a simple web server server in python.
import socket import json dictionary = {'Hello':'World'} dictionary_json = json.dumps(hardware) def parse_request(request): try: parsed = request.split() method = parsed[0] url = parsed[1] return (method, url) except: pass def generate_headers(method, url): if not method == "GET": return ('HTTP/1.1 405 Method not allowed\n\n', 405) return ('HTTP/1.1 200 OK\n\n', 200) def generate_content(code, url): if code == 404: return '<h1>404</h1><p>Not found</p>' if code == 405: return '<h1>405</h1><p>Method not allowed</p>' return dictionary_json def generate_respose(request): method, url = parse_request(request) headers, code = generate_headers(method, url) body = generate_content(code, url) return (headers + body).encode() def run_server(): server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) server_socket.bind(('localhost', 8080)) server_socket.listen() while True: client_socket, addr = server_socket.accept() request = client_socket.recv(1024) print(request) response = generate_respose(request.decode('utf-8')) print(response) client_socket.sendall(response) client_socket.close() If you open a browser and go to localhost: 8080, then the contents of dictionary_json will be displayed on the screen. I would like the contents of the dictionary displayed on request javascript. That is, a simple html page with a button that, if pressed, would display the contents of the dictionary.
The question is actually how can this be implemented in the simplest way? I understand you need to use ajax requests and so on, but then how to process them by the server?