Encode() function does not work in fast html page inside REPLIT

I’m trying to build a simple page using fast html python , inside REPLIT, to send a single carachter with submit button and to get the decimal UNicode value… the method .encode() seems not work…please, some help..

the code:

from fasthtml.common import FastHTML, serve, Div, H1, P

from fasthtml.common import *

app = FastHTML()

carattere=“”

app.get(“/”)

def home():

return Main(H1(‘UNICODE Processor’),

Div(len(carattere), “;”,carattere.encode()),

A(“Link to Page 2 (to add messages)”, href=“/page2”))

app.get(“/page2”)

def page2():

return Main(P(“Add a message with the form below:”),

Form(Input(type=“text”, name=“car”),

Button(“Submit”),

action=“/”, method=“post”))

u/app.post(“/”)

def codifica(car:str):

global carattere

carattere=car

return home()

if _name_ == “_main_”:

serve()

If you want people to look at it properly, please reformat this into a proper markdown code block.

In the mean time,
i) try a simple example in the repr, on something other than an empty string:

carattere=“”

ii) str.encode returns bytes. You can convert a byte string to an integer, but if you want the unicode code point I believe you need `.encode(‘utf32’)'. l

iii) Just put the Div(...) stuff in its own separate helper function taking a string argument, that doesn’t need global carattere

Thank you, just two question …please, could you tell me how put code in proper markdown block and if you could write an exemple of Div () in a separate function, without global.
I apologize, I’m newby…