I have a basic python server, code snippet is below. I want to try accessing it programmatically via javascript and a web browser. First of all, I just want to link a javascript button and have it make a request to the python server to fetch an HTML page.

import socket

server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = ('localhost', 8000)
server_socket.bind(server_address)
server_socket.listen(1)
system
mere paas ek mul paythan sarwar he, code snipet neeche he.main javascript or ek web brouzar ke madhyam se ise programetic rup se acces karne kaa prayaas karnaa chahta hum.sabase pehle, main sirf ek javascript batan ko link karnaa chahta hum or yah ek HTML pej laane ke liye paythan sarwar se anurodh karata he.

aayaat socket

server_socket = socket.socket (socket.af_inet, socket.sock_stream)
server_address = ('localhost', 8000)
server_socket.bind (server_address)
server_socket.listen (1)
user
zarur, main aapaki madad kar saktaa hum.sabase pehle, ham ek GET anurodh shuru karne ke liye ek HTML kankal or ek batan banaaenge.

window.addeventListener ('lod', fnction () {
    mukhya();
});

kaary mukhya () {
    const htmlskel = `
    <! Doctype html>
    <html>
    <head>
    </head>
    <sharir>
    <h1> paythan/javascript phet test </h1>
    <batan idi = "gobton"> lod html </batan>
    <div id = "html-container"> </div>
    </sharir>
    </html>
    `;

    const parentdiv = document.createelement ("div");
    ParetDiv.innerHtml = htmlskel;
    document.body.AppendChild (ParentDiv);
    
    function loadhtml () {
        fetch ('http: // localhost: 8000/html- file') // HTML-FILE samaapan bindu par ek anurodh bhejein
        .then (pratikriya => response.text ())
        .then (html => {
            document.queryselector ('#html-container'). innerhtml = html;// prishth main HTM daalen
        });
    }
    
    const batan listiner = document.getElementByid ("Gobutton")
    ButtonListener.addeventListener ("clic", fnction () {
        loadhtml ()
    })}

aglaa, ham /HTML- file andpoint ke anurodhon ko sanbhaalane ke liye paythan sarwar ko sanshodhit karenge.

aayaat socket

server_socket = socket.socket (socket.af_inet, socket.sock_stream)
server_address = ('localhost', 8000)
server_socket.bind (server_address)
server_socket.listen (1)

jabaki sach:
    client_socket, client_address = server_socket.accept ()
    data = client_socket.recv (1024)
    yadi data:
        sandesh = data.decode ()
        # /HTML-FILE ke liye ek anurodh ke liye dekhen
        yadi Message.StartSwith ("get /html-file"):
            khule ("index.html", 'r') ke saath f:
                html = f.read ()
            pratikriya = "http/1.1 200 ok \ r \ n" \ _
                       "acces-control-wal-origin: *\ r \ n" \ _
                       f "saamagree-lambaai: {len (html)} \ r \ n" \ _
                       "saamagree-prakaar: paath/html \ r \ n \ r \ n" \ _
                       f "{html}"
            client_socket.sendall (response.encode ())
            client_socket.close ()

javascript code main, hamane ek batan clic event ke saath fnction LoadHTML () se judaa he.LoadHtml () fnction /HTML-File samaapan bindu ko GET anurodh bhejtaa he, jise paythan code dwaara niyantrit kiya jaataa he.paythan code Index.html naam kii ek fil main padhata he or apni saamagree ko colling fnction par waapas bhejtaa he, jo ise prishth main sammilit karata he.yah code sarwar code ke rup main ek hi nirdeshika main ek index.html fil kii upasthiti ko maanata he, isliye aapako code ko sanshodhit karne kii aavashyaktaa ho sakati he yadi aapaki HTML fil kaa ek alag naam yaa sthaan he.
assistant
<|system|>
</s>
<|user|>
mere paas ek mul paythan sarwar he, code snipet neeche he.main javascript or ek web brouzar ke madhyam se ise programetic rup se acces karne kaa prayaas karnaa chahta hum.sabase pehle, main sirf ek javascript batan ko link karnaa chahta hum or yah ek HTML pej laane ke liye paythan sarwar se anurodh karata he.

aayaat socket

server_socket = socket.socket (socket.af_inet, socket.sock_stream)
server_address = ('localhost', 8000)
server_socket.bind (server_address)
server_socket.listen (1)</s>
<|assistant|>
zarur, main aapaki madad kar saktaa hum.sabase pehle, ham ek GET anurodh shuru karne ke liye ek HTML kankal or ek batan banaaenge.

window.addeventListener ('lod', fnction () {
    mukhya();
});

kaary mukhya () {
    const htmlskel = `
    <! Doctype html>
    <html>
    <head>
    </head>
    <sharir>
    <h1> paythan/javascript phet test </h1>
    <batan idi = "gobton"> lod html </batan>
    <div id = "html-container"> </div>
    </sharir>
    </html>
    `;

    const parentdiv = document.createelement ("div");
    ParetDiv.innerHtml = htmlskel;
    document.body.AppendChild (ParentDiv);
    
    function loadhtml () {
        fetch ('http: // localhost: 8000/html- file') // HTML-FILE samaapan bindu par ek anurodh bhejein
        .then (pratikriya => response.text ())
        .then (html => {
            document.queryselector ('#html-container'). innerhtml = html;// prishth main HTM daalen
        });
    }
    
    const batan listiner = document.getElementByid ("Gobutton")
    ButtonListener.addeventListener ("clic", fnction () {
        loadhtml ()
    })}

aglaa, ham /HTML- file andpoint ke anurodhon ko sanbhaalane ke liye paythan sarwar ko sanshodhit karenge.

aayaat socket

server_socket = socket.socket (socket.af_inet, socket.sock_stream)
server_address = ('localhost', 8000)
server_socket.bind (server_address)
server_socket.listen (1)

jabaki sach:
    client_socket, client_address = server_socket.accept ()
    data = client_socket.recv (1024)
    yadi data:
        sandesh = data.decode ()
        # /HTML-FILE ke liye ek anurodh ke liye dekhen
        yadi Message.StartSwith ("get /html-file"):
            khule ("index.html", 'r') ke saath f:
                html = f.read ()
            pratikriya = "http/1.1 200 ok \ r \ n" \ _
                       "acces-control-wal-origin: *\ r \ n" \ _
                       f "saamagree-lambaai: {len (html)} \ r \ n" \ _
                       "saamagree-prakaar: paath/html \ r \ n \ r \ n" \ _
                       f "{html}"
            client_socket.sendall (response.encode ())
            client_socket.close ()

javascript code main, hamane ek batan clic event ke saath fnction LoadHTML () se judaa he.LoadHtml () fnction /HTML-File samaapan bindu ko GET anurodh bhejtaa he, jise paythan code dwaara niyantrit kiya jaataa he.paythan code Index.html naam kii ek fil main padhata he or apni saamagree ko colling fnction par waapas bhejtaa he, jo ise prishth main sammilit karata he.yah code sarwar code ke rup main ek hi nirdeshika main ek index.html fil kii upasthiti ko maanata he, isliye aapako code ko sanshodhit karne kii aavashyaktaa ho sakati he yadi aapaki HTML fil kaa ek alag naam yaa sthaan he.</s>
