Skip to main content

Server-side Django adapter for Inertia.js

Project description

django-inertia

GitHub Workflow Status (branch) Python Version PyPI License Code style: black

Django server-side new adapter for Inertia.js.

Getting Started

Install the package

pip install django-inertia

Configure your project

  1. Add the package django_inertia to your project (if you want to use the template tag else it's not necessary).

  2. 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

django-inertia-1.3.0.tar.gz (15.3 kB view hashes)

Uploaded Source

Built Distribution

django_inertia-1.3.0-py3-none-any.whl (8.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page