Skip to content

Tutorial / Reference

This tutorial shows you how to use Django Ninja Extra with most of its features. And most especially assumes you know how to use Django Ninja


A lot of content here is drawn from Django-Ninja. So a lot would make sense if you understand the Django-Ninja framework first.


pip install django-ninja-extra

After installation, add ninja_extra to your INSTALLED_APPS


Create a Django project

(If you already have an existing Django project, skip to the next step).

Start a new Django project (or use an existing one).

django-admin startproject myproject

First steps

Let's create a module for our API. Create an file in the same directory location as

from ninja_extra import NinjaExtraAPI

api = NinjaExtraAPI()

# function definition using Django-Ninja default router
def hello(request):
    return "Hello world"

Now go to and add the following:

from django.contrib import admin
from django.urls import path
from .api import api

urlpatterns = [
    path("api/", api.urls),

Defining operation methods

"Operation" can be one of the HTTP "methods":

  • GET
  • POST
  • PUT
  • ... and more.

These are Django-Ninja defined operations on the API or Django-Ninja router. The same operation is exposed to APIControllers with the route class. The route class is an extra decorator that converts APIController instance methods to route function or endpoint.

On the other hand, the router here is a short form of the ControllerRouter class, an adapter class, which is an that only adapts APIController to the Django-Ninja router. It also provides global control of all routes defined in any APIController class.

from ninja_extra import (
    http_get, http_post, http_put, http_delete, http_patch, http_generic
from ninja.constants import NOT_SET

@api_controller('', tags=['My Operations'], auth=NOT_SET, permissions=[])
class MyAPIController:
    def get_operation(self):

    def post_operation(self):

    def put_operation(self):

    def delete_operation(self):

    def patch_operation(self):

    # If you need to handle multiple methods with a single function, you can use the `generic` method as shown above
    @http_generic(["POST", "PATCH"]) 
    def mixed(request):

To have a complete Controller setup, the APIController must be decorated with ControllerRouter before it's been registered.