Analyzer::Python::DjangoNinja
Inherits Analyzer::Python::PythonEngine < Analyzer < FileHelper < Reference < Object
Django Ninja is a FastAPI-inspired REST framework that plugs into
Django's URL system. Operations are declared with decorators on a
NinjaAPI() (or Router()) instance — @api.get("/items") — and
the whole API is mounted through Django's URLconf:
api.py
from ninja import NinjaAPI, Router api = NinjaAPI()
@api.get("/add") def add(request, a: int, b: int): ...
router = Router() @router.get("/{event_id}") def event(request, event_id: int): ... api.add_router("/events/", router)
urls.py
urlpatterns = [path("api/", api.urls)]
The full URL is mount_prefix + router_prefix + operation_path, so
the analyzer works in phases: collect NinjaAPI/Router instances
and their operations, resolve each API's mount prefix from the
URLconf, resolve router prefixes from add_router(...), then emit
one endpoint per (instance, prefix) reachable from an API root.
Constants
Verbs exposed as @api.<verb>(...) decorators. api_operation
(an explicit method list) is handled separately.
path("api/", "myproject.api.api.urls") — the dotted-string form.
path("api/", api.urls) / re_path(r"^api/", api.urls) — a router
instance mounted by attribute reference.
django-ninja path parameters use Django's converter syntax, where
the converter (when present) comes BEFORE the name: {item_id} or
{int:item_id}. This is the reverse of FastAPI's {item_id:int},
so the capture takes the token AFTER an optional converter:.
Class methods
Instance methods
Instance-side view of the same declaration. The per-file rescues live on
this base class, which has no way to name the analyzer that is running
inside them, so a skipped file could not be attributed to a tech.
Deriving it from analyzer_for keeps the name written exactly once.