-
-
Notifications
You must be signed in to change notification settings - Fork 526
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
When I'm using the interface written by Ninja Router, I can't access it properly.
Demo is here: https://github.com/guozhenyi/django-ninja-bug-20250919
Versions (please complete the following information):
- Python version: [e.g. 3.8]
- Django version: [e.g. 4.2]
- Django-Ninja version: [e.g. 1.4.3]
Note you can quickly get this by runninng this command:
git clone https://github.com/guozhenyi/django-ninja-bug-20250919.git
cd django-ninja-bug-20250919
python manage.py runserver
Use Postman or Bruno, and visit POST /api/users and PUT /api/users.
Create a Ninja router:
apps/core/api.py
:
from typing import Optional
from django.http import HttpRequest
from ninja import Router, Schema
router = Router()
class UserPutSchema(Schema):
id: int
username: str
email: Optional[str] = None
@router.put("/users")
def user_update(request: HttpRequest, rdata: UserPutSchema):
data = {"code": 200}
return data
Create mysite/api.py:
from typing import Optional
from django.http import HttpRequest
from ninja import NinjaAPI, Schema
from apps.core.api import router as core_router
api = NinjaAPI()
class UserPostSchema(Schema):
username: str
password: str
email: Optional[str] = None
@api.post("/users")
def user_create(request: HttpRequest, rdata: UserPostSchema):
data = {"code": 200}
return data
api.add_router("", core_router)
Request result:
Normally, these should all OK.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working