Skip to content

Commit

Permalink
fixed the example in the documentation as well
Browse files Browse the repository at this point in the history
  • Loading branch information
volfpeter committed Jan 24, 2024
1 parent 820bac9 commit 2003d8c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,15 @@ def render_user_list(result: list[dict[str, str]], *, context: dict[str, Any], r
users = "".join(("<ul>", *(f"<li>{u.name}</li>" for u in result), "</ul>"))
return f"{lucky_number}\n{users}"


@app.get("/htmx-or-data")
@hx(render_user_list)
def htmx_or_data(random_number: DependsRandomNumber) -> list[dict[str, str]]:
return [{"name": "Joe"}]


@app.get("/htmx-only")
@hx(render_user_list, no_data=True)
async def htmx_only(random_number: DependsRandomNumber) -> list[dict[str, str]]:
return [{"name": "Joe"}]

```

## Dependencies
Expand Down
7 changes: 5 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,14 @@ def htmx_only() -> dict[str, list[dict[str, str]]]:
Custom templating offers more flexibility than the built-in `Jinja` renderer by giving access to all dependencies of the decorated route to the renderer function:

```python
from typing import Annotated
from typing import Annotated, Any

from fastapi import Depends, FastAPI
from fastapi import Depends, FastAPI, Request
from fasthx import hx

# Create the app.
app = FastAPI()

# Create a dependecy to see that its return value is available in the render function.
def get_random_number() -> int:
return 4 # Chosen by fair dice roll.
Expand Down

0 comments on commit 2003d8c

Please sign in to comment.