Inertia Django
raw JSON → 1.2.0 verified Fri May 01 auth: no python
Django adapter for the Inertia.js framework to build single-page-app-like experiences without an API. Current version 1.2.0, supports Python >=3.8 <4.0, release cadence is irregular.
pip install inertia-django Common errors
error ModuleNotFoundError: No module named 'inertia' ↓
cause Package not installed or imported using old name (`django-inertia`).
fix
Install
inertia-django and import as from inertia import ... error TemplateDoesNotExist at / ↓
cause Inertia view returned a template response instead of Inertia response because `render_inertia` was not used.
fix
Use
render_inertia(request, component_name, props) instead of render(request, template) error CSRF Failed: CSRF token missing or incorrect. ↓
cause The Inertia frontend did not send the CSRF token in the `X-CSRFToken` header.
fix
Ensure your frontend reads the CSRF token from the cookie and sets the header on every request.
Warnings
breaking In version 1.0 the package was renamed from `django-inertia` to `inertia-django` and the internal module structure changed. All imports from `inertia` must be updated. ↓
fix Update imports: `from inertia import ...`
gotcha CSRF token handling: Inertia expects the CSRF token to be sent via the `X-CSRFToken` header, not the cookie alone. Missing middleware configuration will cause 403 errors. ↓
fix Ensure `django.middleware.csrf.CsrfViewMiddleware` is enabled and your frontend sends the header.
deprecated The `inertia.contrib` submodule is deprecated and will be removed in a future release. Use the core `inertia` module directly. ↓
fix Replace `from inertia.contrib import ...` with `from inertia import ...`
Imports
- InertiaMiddleware wrong
from inertia.middleware import inertia_middlewarecorrectfrom inertia.middleware import InertiaMiddleware - render_inertia
from inertia import render_inertia - share
from inertia import share
Quickstart
from inertia import render_inertia
from django.views import View
class HomeView(View):
def get(self, request):
return render_inertia(request, 'Home', {'user': {'name': 'John'}})