Hi!
I am having the following scenario using the dataclass decorator with a class
When returning multiple elements in the __ft__ function I am getting a JSON representation of the class instead of HTML elements
Code:
# /src/pages/home/home_page.py
from fasthtml.common import *;
@dataclass
class HomePage:
def __ft__(self):
return H1('HomePage'), Div('hello!');
# main.py
from fasthtml.common import *
from src.pages.home.home_page import *;
def e404_handler(req,exc):
return Titled('Page not found');
app, route = fast_app(exception_handlers={404: e404_handler});
@route('/')
def get():
return HomePage();
I also tried:
@dataclass
class HomePage:
def __ft__(self):
return Titled('HomePage', Div('hello'))
Result:
I had to rewrite the __tf__ function as follows in order to get it work:
# /src/pages/home/home_page.py
from fasthtml.common import *;
@dataclass
class HomePage:
def __ft__(self):
return Div(H1('HomePage'), Div('hello!'));
Hi! I am having the following scenario using the dataclass decorator with a class When returning multiple elements in the
__ft__
function I am getting a JSON representation of the class instead of HTML elements Code:I also tried:
Result:
I had to rewrite the
__tf__
function as follows in order to get it work: