Arduino Portenta H7 - Webserver Output

Hello together,

I would like to visualize measurement values via Web Server functionalities.
Therefore I implemented a WLAN Access Point in my Portenta H7, that provides a Website under the follwing Adress: http://192.168.4.1

Right now, I’m struggeling to implement Python Variables into the HTML output.
In this case the variable “var1” is defined as global variable.
How can I access the content of “var1” in the web_page function?

Thank you.

try:
  import usocket as socket
except:
  import socket

import time, network, gc


gc.collect()

#https://forums.openmv.io/t/portenta-h7-lite-connected-access-point-not-working/7416

SSID ='OPENMV_AP'   # Network SSID
KEY  ='1234567890'  # Network key (must be 10 chars)
HOST = ''           # Use first available interface
PORT = 8080         # Arbitrary non-privileged port


# Init wlan module in AP mode.
wlan = network.WLAN(network.AP_IF)
wlan.deinit()
wlan.config(essid=SSID, channel=11, password=KEY)
wlan.active(True)

global var1
var1 = "12345"

print("Connect to: ", wlan.ifconfig())

while (len(wlan.status("stations")) == 0):
    print("Waiting for a station to connect...")
    time.sleep_ms(1000)

print("Station connected", ':'.join(["%x"%(x) for x in wlan.status("stations")[0][0]]))

def web_page():
  html = """<html>
  <head><meta name="viewport" content="width=device-width, initial-scale=1"></head>
  <body>
  <h1>Hello, World!</h1>
  <p>
  <span>str(var1)</span>
  </p>
  </body>
  </html>"""
  return html

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 80))
s.listen(5)

while True:
  conn, addr = s.accept()
  print('Got a connection from %s' % str(addr))
  request = conn.recv(1024)
  print('Content = %s' % str(request))
  response = web_page()
  conn.send(response)
  conn.close()

# http://192.168.4.1

Hi, you should use chatGPT when you have general purpose Python questions:

html = """<html>
  <head><meta name="viewport" content="width=device-width, initial-scale=1"></head>
  <body>
  <h1>Hello, World!</h1>
  <p>
  <span>{}</span>
  </p>
  </body>
  </html>""".format(var1)
  return html

Ok, thank you