Skip to content

Commit

Permalink
improve htmx example
Browse files Browse the repository at this point in the history
  • Loading branch information
livioribeiro committed Dec 18, 2023
1 parent 9de0425 commit 89bb4c4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
8 changes: 7 additions & 1 deletion examples/htmx/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@ async def index(self, request: Request):
@post("/clicked")
async def clicked(self, request: Request):
self.click_count += 1
await self.template.respond(request.response, "clicked.html", {"click_count": self.click_count})

rendered = await self.template.render(
"click-count.html",
{"click_count": self.click_count}
)

await respond_text(request.response, rendered + "Clicked!")
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
Clicked!

<span id="click-count" hx-swap-oob="true">{{ click_count }}</span>
2 changes: 1 addition & 1 deletion examples/htmx/resources/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Click count: <span id="click-count">{{ click_count }}</span>
</div>

<button hx-post="/clicked" hx-swap="outerHTML">
<button hx-post="/clicked" hx-swap="innerHTML">
Click Me
</button>

Expand Down

0 comments on commit 89bb4c4

Please sign in to comment.