simplesite
simplesite copied to clipboard
The hx-request header creates error when using back button in browser
On 04_htmx
branch:
When visiting the "/catalog" endpoint, artist cards are generated. An htmx event toggles from Artist/Members to Artist/Profile displayed (see below):
Clicking on the "MORE INFO" link sends you outside of the app (but it also triggers an hx-request). Since this is an hx-request, it triggers this bit of code in routes.py
:
if request.headers.get("hx-request"):
id = request.headers.get("HX-Trigger")
artist = db.find("id", int(id))
print(artist)
return templates.TemplateResponse(
"artist/profile.html",
{
"request": request,
"artist": artist[0],
"get_website": get_website,
"get_profile": get_profile,
}
)
At this point, there is no longer an HX-Trigger
, which means that the db.find("id", int(id))
is creating a ValueError.
When a user uses the "back" button in their browser to return to the "/catalog" endpoint, they receive an Internal Server Error.
May be able to fix by adding condition to check for "HX-Trigger", but need to make sure response is correct for what the user is trying to do.