Skip to content

The hx-request header creates error when using back button in browser #3

@tataraba

Description

@tataraba

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):

image

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions