'Send request to frontend to reload webpage Python

I am trying to send a request to the frontend to reload the page when requested. I am http.server and socketserver. This is my handler class:

class _ServerHandler(http.server.SimpleHTTPRequestHandler):
    def _set_headers(self):
        self.send_response(200)
        self.send_header('Content-Type', 'text/html')
        self.send_header('Content-Length', os.path.getsize(self.getPath()))
        self.end_headers()

    def getPath(self):
        if self.path == '/':
            content_path = os.path.join(
                _sysargvData['cd'], _RESERVED._HOMEPAGEHTMLPATH)
        else:
            content_path = os.path.join(_sysargvData['cd'], str(self.path).split('?')[0][1:])
        return content_path

    def getContent(self, content_path):
        with open(content_path, mode='r', encoding='utf-8') as f:
            content = f.read()
        return bytes(content, 'utf-8')

    def do_GET(self):
        if self.path.startswith('/kill'):
            self.send_error(500)
            log('SERVER: GET "/kill", killing server')
            httpd.shutdown()
        self._set_headers()
        self.wfile.write(self.getContent(self.getPath()))

How do I send a request to the frontend to automatically reload the page whenever something changes? Also how can I send data to the frontend so I can use js to edit the html? thx



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source