Im trying to create a web page that uses CSS to format it easier, however this did not work at first so i found this forum that solved the problem by removing the f at the start of declaring the HTML website. This solved the issues with the CSS (as it no longer read what was inside the CSS as python, but as Java) But creating a new issuing that meant i couldn't send data from thonny to the web page. I want to send a value from thonny then use it in the webpage this can be done by adding back the f, but then any css stops working, is there a way to get both the css and sending data from thonny to the webpage workig simutanlosy?
More notes in the code ( please ask anything you may not understand as my code may be quite messy)
The forum
viewtopic.php?p=2165078&hilit=css+webpage+pico#p2165078
My code:
More notes in the code ( please ask anything you may not understand as my code may be quite messy)
The forum
viewtopic.php?p=2165078&hilit=css+webpage+pico#p2165078
My code:
Code:
import networkimport socketfrom time import sleepimport machinessid = '####'password = '#######'def webpage(data): html = f""" <!DOCTYPE html> <html> <head> <style>//the css is not working because i have the f h1{ border: 10px; border-color: rgb(255,255,255); font-family: verdana; font-size: 4px; text-align:center; color: rgb(150,150,150); } </style> <h1> hello </h1> <p>Hello: {data}</p>//this returns as Hello: 90, but ifi was to remove the f to get the css working it would read Hello: {data} <input type="range" min="1" max="100" value="{data}" id="myRange"> </body> </html> """ return str(html)def connect(): #Connect to WLAN wlan = network.WLAN(network.STA_IF) wlan.active(True) wlan.connect(ssid, password) while wlan.isconnected() == False: print('Waiting for connection...') sleep(1) ip = wlan.ifconfig()[0] print(f'Connected on {ip}') return ipdef open_socket(ip): # Open a socket address = (ip, 80) connection = socket.socket() connection.bind(address) connection.listen(1) return connectiondef serve(connection): #Start a web server state = 'OFF' temperature = 0 while True: client = connection.accept()[0] request = client.recv(1024) request = str(request) try: request = request.split()[1] except IndexError: pass html = webpage(90) #the data client.send(html) client.close()try: ip = connect() connection = open_socket(ip) serve(connection)except KeyboardInterrupt: machine.reset()
Statistics: Posted by crispybacon999 — Fri Apr 05, 2024 6:05 pm — Replies 1 — Views 42