Skip to content

Commit

Permalink
Merge branch 'master' of github.com:vitalik/django-ninja
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalik committed Dec 29, 2024
2 parents c4a6242 + 064b543 commit 863e832
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions docs/docs/guides/routers.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,38 @@ Now you have the following endpoints:
Great! Now go have a look at the automatically generated docs:

![Swagger UI Nested Routers](../img/nested-routers-swagger.png)

### Nested url parameters

You can also use url parameters in nested routers by adding `= Path(...)` to the function parameters:

```python hl_lines="13 16"
from django.contrib import admin
from django.urls import path
from ninja import NinjaAPI, Path, Router

api = NinjaAPI()
router = Router()

@api.get("/add/{a}/{b}")
def add(request, a: int, b: int):
return {"result": a + b}

@router.get("/multiply/{c}")
def multiply(request, c: int, a: int = Path(...), b: int = Path(...)):
return {"result": (a + b) * c}

api.add_router("add/{a}/{b}", router)

urlpatterns = [
path("admin/", admin.site.urls),
path("api/", api.urls),
]
```

This will generate the following endpoints:

```
/api/add/{a}/{b}
/api/add/{a}/{b}/multiply/{c}
```

0 comments on commit 863e832

Please sign in to comment.