fasthtml icon indicating copy to clipboard operation
fasthtml copied to clipboard

[BUG] FastHTML by Example should use a redirect for POST instead of render

Open zdrummond opened this issue 5 months ago • 0 comments

Describe the bug This is more a "bug"/question about the tutorial. I was following along and noticed when I got to the WebPage->Web App section that things did not work in the browser.

  1. There seemed to be some loop (that I can not repo) that caused the page to keep adding the last item I submitted
  2. After you add an items and get back to the home page, if you refresh the page it wants to do another form submission

Feels like both issues are because the POST renders the home page instead of redirecting

@app.post("/")
def add_message(data:str):
    messages.append(data)
    return home()

vs

@app.post("/")
def add_message(data: str):
    messages.append(data)
    return RedirectResponse("/", status_code=302)

Expected behavior If I am follow a demo, the demo produces best practice web patterns. I had to go looking through GitHub example repos to even find that RedirectResponse is the right way to do this.

Environment Information Please provide the following version information:

  • fastlite version: "0.0.9"
  • fastcore version:"1.7.3"
  • fasthtml version:"0.5.1"

Confirmation Please confirm the following:

  • [x] I have read the FAQ (https://docs.fastht.ml/explains/faq.html)
  • [x] I have provided a minimal reproducible example
  • [x] I have included the versions of fastlite, fastcore, and fasthtml
  • [x] I understand that this is a volunteer open source project with no commercial support.

Additional context Note: problem #1 might have been because I was using an earlier version of fasthtml and recently updated, but #2 to exists still.

zdrummond avatar Sep 02 '24 18:09 zdrummond