Skip to content

Commit

Permalink
Merge pull request #1010 from jonklo/documentation-fixes
Browse files Browse the repository at this point in the history
Minor documentation tweaks
  • Loading branch information
vitalik authored Dec 15, 2023
2 parents c548ea5 + 053ff0c commit d0a2fff
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/docs/guides/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ And, if you need to overrule some of those methods, you can do that on the opera
### Custom function


The "`auth=`" argument accepts any Callable object. **NinjaAPI** passes authentication only if the callable object returns a value that can be **converted to boolean True**. This return value will be assigned to the `request.auth` attribute.
The "`auth=`" argument accepts any Callable object. **NinjaAPI** passes authentication only if the callable object returns a value that can be **converted to boolean `True`**. This return value will be assigned to the `request.auth` attribute.

```python hl_lines="1 2 3 6"
{!./src/tutorial/authentication/code002.py!}
Expand Down
6 changes: 3 additions & 3 deletions docs/docs/guides/routers.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ from events.api import router as events_router

api = NinjaAPI()

api.add_router("/events/", events_router) # You can add router object
api.add_router("/news/", "news.api.router") # or well add router by python path
api.add_router("/events/", events_router) # You can add a router as an object
api.add_router("/news/", "news.api.router") # or by Python path
api.add_router("/blogs/", "blogs.api.router")
```

Expand Down Expand Up @@ -156,7 +156,7 @@ router = Router(tags=["events"])
## Nested routers

There are also times when you need to split your logic up even more.
**Django Ninja** makes it possible to include a router into another router as many times as you like, and finally include the top level router into the main api instance.
**Django Ninja** makes it possible to include a router into another router as many times as you like, and finally include the top level router into the main `api` instance.


Basically, what that means is that you have `add_router` both on the `api` instance and on the `router` instance:
Expand Down
2 changes: 2 additions & 0 deletions docs/docs/tutorial/step3.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
We'll create a third operation that will return information about the current Django user.

```python
from ninja import Schema

class UserSchema(Schema):
username: str
is_authenticated: bool
Expand Down
4 changes: 2 additions & 2 deletions docs/src/tutorial/authentication/code002.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ def ip_whitelist(request):
return "8.8.8.8"


@api.get("/ipwhiltelist", auth=ip_whitelist)
def ipwhiltelist(request):
@api.get("/ipwhitelist", auth=ip_whitelist)
def ipwhitelist(request):
return f"Authenticated client, IP = {request.auth}"
4 changes: 2 additions & 2 deletions tests/test_docs/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ def test_examples():

client = TestClient(api)

response = client.get("/ipwhiltelist", META={"REMOTE_ADDR": "127.0.0.1"})
response = client.get("/ipwhitelist", META={"REMOTE_ADDR": "127.0.0.1"})
assert response.status_code == 401
response = client.get("/ipwhiltelist", META={"REMOTE_ADDR": "8.8.8.8"})
response = client.get("/ipwhitelist", META={"REMOTE_ADDR": "8.8.8.8"})
assert response.status_code == 200

# Api key --------------------------------
Expand Down

0 comments on commit d0a2fff

Please sign in to comment.