Server-side Django adapter for Inertia.js
Project description
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 %}
{% 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>
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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-inertia-1.3.0.tar.gz
.
File metadata
- Download URL: django-inertia-1.3.0.tar.gz
- Upload date:
- Size: 15.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 101850375f821401597b6285707815226f95423abd6f13a60009d16b9143c15d |
|
MD5 | fa34779fdabf75e6da28fee845789416 |
|
BLAKE2b-256 | d9950a04a26cb09a42e74ab970da11ea32bdbbf5189918d6a9e166488f03e40b |
File details
Details for the file django_inertia-1.3.0-py3-none-any.whl
.
File metadata
- Download URL: django_inertia-1.3.0-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f881e647db359bd188a4a5446adb202b671b8b7363f68e4a258d0cece5b8efbb |
|
MD5 | 7877004f4e8dd74926ad3436675fcbac |
|
BLAKE2b-256 | da5c5581f92e2ada305cc4ca52bbf5fef926ea6b651ba6225161292340b46487 |