Django server-side new adapter for Inertia.js.
DEPRECATED. This project is now supported by Bellawatt: https://github.com/inertiajs/inertia-django
pip install django-inertia
-
Add the package
django_inertia
to your project (if you want to use the template tag else it's not necessary). -
Add
InertiaMiddleware
to your project middlewares:
MIDDLEWARES = [
#...,
"django_inertia.middleware.InertiaMiddleware",
]
To create and inertia response you need to use Inertia.render()
method:
from django_inertia import Inertia
def event_detail(request, id):
event = Event.objects.get(pk=id)
props = {
'event': {
'id':event.id,
'title': event.title,
'start_date': event.start_date,
'description': event.description
}
}
return Inertia.render(request, "Event/Show", props)
{% load inertia_tags %}
{% load static %}
<!DOCTYPE html>
<html class="h-full bg-gray-200">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<script src="{% static 'dist/app.js' %}" defer></script>
<link href="{% static 'dist/app.css' %}" rel="stylesheet" />
</head>
<body>
{% inertia %}
</body>
</html>
TODO
Inertia.share()
Inertia.render()
Inertia.version()
Inertia.get_version()
Inertia.flush_shared()
Inertia.lazy()
Inertia.static()
Thanks to Andres Vargas for the inspiration on this package. Here is the link to its legacy package which seems not be actively maintained anymore: inertia-django
TODO
django-inertia is open-sourced software licensed under the MIT license.