django-inertia
Django server-side new adapter for Inertia.js.
Getting Started
Install the package
pip install django-inertia
Configure your project
-
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",
]
Creating responses
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)
Loading data into your template
{% load inertia_tags %}
<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_URL}}dist/app.js" defer>script>
<link href="{{ STATIC_URL}}dist/app.css" rel="stylesheet" />
head>
<body>
{% inertia %}
body>
html>
Full documentation
TODO
Inertia.share()
Inertia.render()
Inertia.version()
Inertia.get_version()
Inertia.flush_shared()
Inertia.lazy()
Inertia.static()
Credits
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
Contributing
TODO
Maintainers
License
django-inertia is open-sourced software licensed under the MIT license.