Open jnchacon opened 2 months ago
I think the examples in this repo are a little out of date as it was one of the first FastHTML demos Jeremy presented.
For example here is an updated working version of simple01.py:
from fasthtml.common import *
app,rt = fast_app()
@rt('/')
def get():
contents = Div(
A('Link', hx_get='/page'),
Card('hi'),
)
return PageX('Home', contents)
@rt('/page')
def get():
contents = Div(
A('Home', hx_get='/'),
)
return PageX('Page', contents)
serve()
@jph00 The examples in this repo aren't too complicated. I can submit a PR if you want them updated? Or prerhaps just add a note to the readme to mention these examples are outdated, and add a link to the official example repos.
Good suggestion - I've updated the readme. I'd be happy to accept a PR too though, if you're interested, since that way this repo would match the tutorial video.
Good suggestion - I've updated the readme. I'd be happy to accept a PR too though, if you're interested, since that way this repo would match the tutorial video.
I don't mind updating the examples. I just wanted to check though the usage of Titled
was correct when replacing the now removed PageX
component. I found that when directly replacing PageX
with Titled
, it needed extra attributes to work as expected to update the browser URL.
from fasthtml.common import *
app,rt = fast_app(live=true)
@rt('/')
def get():
contents = Div(
A('Link', hx_get='/page', hx_target='body', hx_push_url='true'),
Card('hi'),
)
return Titled('Home', contents)
@rt('/page')
def get():
contents = Div(
A('Home', hx_get='/', hx_target='body', hx_push_url='true'),
)
return Titled('Page', contents)
serve()
This works as expected. Is this the correct approach? Using hx_boost='true'
along with the href
attribute also works. Do you have a preference?
Thanks for checking. Yes Titled is good to get the right formatting. And I think using href is a good change - afaict we don't actually need hx_boost for this example to work correctly?
Message ID: @.***>
That's right. The example will work fine with just href
and no hx_boost
, but it will replace the whole page HTML by default. Using hx_boost
(as you know) makes this a little smoother as only the innerHTML
of the body
is replaced.
I guess we can keep it minimal for this simple example:
from fasthtml.common import *
app,rt = fast_app(live=true)
@rt('/')
def get():
contents = Div(
A('Link', href='/page'),
Card('hi'),
)
return Titled('Home', contents)
@rt('/page')
def get():
contents = Div(
A('Home', href='/'),
)
return Titled('Page', contents)
serve()
FYI, I'll be taking a look at the updates this week, just to let you know I'm still interested in doing this. :)
when running simple01.py
... app = fast_app() rt = app.route ...
get this error:
AttributeError: 'tuple' object has no attribute 'route'
when running simple02.py: ... app,todos,Todo = fast_app('data/todos.db', id=int, title=str, done=bool, pk='id') rt = app.route ....
get his error:
ValueError: too many values to unpack (expected 3)
I think that this examples are for a previous version when the returned objects are different.
Also, the FT functions are not recognized.