Skip to content

Add django-ninja as REST API option#6088

Merged
browniebroke merged 25 commits intocookiecutter:mainfrom
browniebroke:feat/django-ninja
Mar 1, 2026
Merged

Add django-ninja as REST API option#6088
browniebroke merged 25 commits intocookiecutter:mainfrom
browniebroke:feat/django-ninja

Conversation

@browniebroke
Copy link
Member

@browniebroke browniebroke commented Oct 2, 2025

Description

  • Change use_drf=y/n option to rest_api=None/DRF/Django Ninja
  • Update all existing mentions of DRFs to the new style
  • Add a few jobs on CI to cover REST API + username field combinations
  • Add a similar level of functionality and testing as DRF with Django Ninja

Checklist:

  • I've made sure that tests are updated accordingly (especially if adding or updating a template option)
  • I've updated the documentation or confirm that my change doesn't require any updates

Rationale

While DRF is a solid option, Django Ninja has gained popularity over the years and is the only other option listed in the ecosystem page.

Fix #4923

Disclaimer

I'm not super familiar with Django Ninja, so I might not have gone with the most idiomatic way to write view and schema. That might be an area of focus if you're more familiar with the framework.

@soccer99
Copy link

I pulled this for my newest project and its working well for me!

@shdwkl
Copy link

shdwkl commented Feb 28, 2026

does this pr planned to get merged

@browniebroke
Copy link
Member Author

does this pr planned to get merged

Yes, at some point, was waiting for folks to try it out and share their experience.

# Conflicts:
#	{{cookiecutter.project_slug}}/pyproject.toml
#	{{cookiecutter.project_slug}}/requirements/base.txt
#	{{cookiecutter.project_slug}}/requirements/local.txt
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new rest_api Cookiecutter option to support choosing between no REST API, Django REST Framework, or Django Ninja, and updates the generated project scaffold, tests, and CI matrix accordingly.

Changes:

  • Replaces use_drf with rest_api across template config, dependencies, and documentation.
  • Introduces Django Ninja API scaffolding (router, schemas, URL wiring) alongside DRF.
  • Expands CI and template-generation coverage for REST API + username-type combinations.

Reviewed changes

Copilot reviewed 20 out of 21 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/views.py Minor formatting tweak to method signature spacing.
{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tests/api/test_views.py Adds Ninja API view tests and gates DRF tests behind rest_api.
{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tests/api/test_urls.py Adds Ninja URL name/path assertions and gates DRF vs Ninja URL tests.
{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tests/api/test_openapi.py Switches OpenAPI/docs URL assertions based on selected REST API.
{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/api/views.py Adds Ninja router endpoints alongside DRF ViewSet under rest_api.
{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/api/schema.py Adds Ninja ModelSchema definitions for user API responses/updates.
{{cookiecutter.project_slug}}/requirements/local.txt Updates DRF-stubs conditional to use rest_api.
{{cookiecutter.project_slug}}/requirements/base.txt Adds django-ninja dependencies under rest_api selection.
{{cookiecutter.project_slug}}/pyproject.toml Updates mypy DRF plugin conditional to use rest_api.
{{cookiecutter.project_slug}}/manage.py Adds a blank line after module docstring.
{{cookiecutter.project_slug}}/config/urls.py Wires DRF vs Ninja API URLs based on rest_api.
{{cookiecutter.project_slug}}/config/settings/production.py Updates DRF-only settings blocks to key off rest_api.
{{cookiecutter.project_slug}}/config/settings/local.py Reformats EMAIL_BACKEND env call (line wrapping).
{{cookiecutter.project_slug}}/config/settings/base.py Adds Ninja installed apps and enables CORS middleware for any REST API choice.
{{cookiecutter.project_slug}}/config/api.py Introduces Ninja NinjaAPI instance and router registration for users.
tests/test_cookiecutter_generation.py Adds new context cases for rest_api values and removes use_drf.
hooks/post_gen_project.py Removes DRF/Ninja starter files depending on selected rest_api option.
docs/1-getting-started/project-generation-options.rst Documents new rest_api option and adds Django Ninja link.
cookiecutter.json Adds rest_api option and removes use_drf.
README.md Updates example prompts to include rest_api selection.
.github/workflows/ci.yml Updates CI matrix and adds jobs covering DRF/Ninja + username combinations.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 20 out of 21 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 20 out of 21 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@browniebroke browniebroke merged commit 9a15b06 into cookiecutter:main Mar 1, 2026
22 checks passed
@browniebroke browniebroke deleted the feat/django-ninja branch March 1, 2026 19:09
@browniebroke
Copy link
Member Author

Let's give this a try

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adding django-ninja options to building REST APIs

4 participants