Django server-side adapter for Inertia.js

Related tags

Djangodjango-inertia
Overview

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

{% inertia %} ">
{% 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.

You might also like...
django-quill-editor makes Quill.js easy to use on Django Forms and admin sites
django-quill-editor makes Quill.js easy to use on Django Forms and admin sites

django-quill-editor django-quill-editor makes Quill.js easy to use on Django Forms and admin sites No configuration required for static files! The ent

A Django chatbot that is capable of doing math and searching Chinese poet online. Developed with django, channels, celery and redis.

Django Channels Websocket Chatbot A Django chatbot that is capable of doing math and searching Chinese poet online. Developed with django, channels, c

A handy tool for generating Django-based backend projects without coding. On the other hand, it is a code generator of the Django framework.
A handy tool for generating Django-based backend projects without coding. On the other hand, it is a code generator of the Django framework.

Django Sage Painless The django-sage-painless is a valuable package based on Django Web Framework & Django Rest Framework for high-level and rapid web

A beginner django project and also my first Django project which involves shortening of a longer URL into a short one using a unique id.

Django-URL-Shortener A beginner django project and also my first Django project which involves shortening of a longer URL into a short one using a uni

Dockerizing Django with Postgres, Gunicorn, Nginx and Certbot. A fully Django starter project.

Dockerizing Django with Postgres, Gunicorn, Nginx and Certbot 🚀 Features A Django stater project with fully basic requirements for a production-ready

pytest-django allows you to test your Django project/applications with the pytest testing tool.

pytest-django allows you to test your Django project/applications with the pytest testing tool.

APIs for a Chat app. Written with Django Rest framework and Django channels.
APIs for a Chat app. Written with Django Rest framework and Django channels.

ChatAPI APIs for a Chat app. Written with Django Rest framework and Django channels. The documentation for the http end points can be found here This

django-dashing is a customisable, modular dashboard application framework for Django to visualize interesting data about your project. Inspired in the dashboard framework Dashing
django-dashing is a customisable, modular dashboard application framework for Django to visualize interesting data about your project. Inspired in the dashboard framework Dashing

django-dashing django-dashing is a customisable, modular dashboard application framework for Django to visualize interesting data about your project.

Django-MySQL extends Django's built-in MySQL and MariaDB support their specific features not available on other databases.
Django-MySQL extends Django's built-in MySQL and MariaDB support their specific features not available on other databases.

Django-MySQL The dolphin-pony - proof that cute + cute = double cute. Django-MySQL extends Django's built-in MySQL and MariaDB support their specific

Comments
  • Add type annotations

    Add type annotations

    This should be mostly correct, I'm a little unsure whether the request parameter in assertations.py is HttpRequest or something else though. I also fixed a potential issue for users that define their own setting for INERTIA_PAGE_CONTEXT. Closes #2

    Also just realized that my code should be formatted with black, I'll do that later. Let me know if you have any other style preferences too.

    opened by pmdevita 2
  • Generated value for data-page not JSON-parsable

    Generated value for data-page not JSON-parsable

    Got this error:

    Uncaught (in promise) SyntaxError: Unexpected token ' in JSON at position 1
        at JSON.parse (<anonymous>)
        at exports.createInertiaApp (index.js?4bf4:1:9213)
        at eval (app.js?5e94:7:17)
        at Module../demo/static/src/app.js (app.js:455:1)
        at __webpack_require__ (app.js:797:42)
        at app.js:861:37
        at app.js:863:12
    

    I believe this is because the generated data-page attribute string:

    <div id="app" data-page="{'component': 'Dashboard/Index', 'props': {'errors': False, 'success': False}, 'url': '/', 'version': '1'}"></div>
    

    is not valid JSON, hence the error.

    Valid JSON should be:

    • double quotes, not single quotes
    • False is not a valid keyword in JSON, but false is (with a lower cap "f")

    Below is a screenshot of the error: image

    No errors after manually editing the generated data-page attribute string to a valid JSON string:

    image

    bug 
    opened by mujahidfa 2
  • Use idiomatic Django to reference static files

    Use idiomatic Django to reference static files

    Hi @girardinsamuel!

    Just thought to improve the docs a bit by using Django's static template tag to reference the generated JS and CSS files in the template. I believe this is more idiomatic Django over using using {{ STATIC_URL }} directly in the template (unless there's another reason that I'm not aware of for it).

    Reference: https://docs.djangoproject.com/en/4.0/howto/static-files/#configuring-static-files

    Great work with this library btw 👍👍

    Thanks!

    opened by mujahidfa 1
Releases(v1.3.0)
  • v1.3.0(May 12, 2022)

    Changed

    • Used idiomatic Django to reference static files by @mujahidfa in https://github.com/girardinsamuel/django-inertia/pull/6

    Fixed

    • Ensured valid JSON string is generated in the data-page attr by @mujahidfa in https://github.com/girardinsamuel/django-inertia/pull/8

    New Contributors

    • @mujahidfa made their first contribution in https://github.com/girardinsamuel/django-inertia/pull/6

    Full Changelog: https://github.com/girardinsamuel/django-inertia/compare/v1.2.0...v1.3.0

    Source code(tar.gz)
    Source code(zip)
  • v1.2.0(Apr 26, 2022)

    Changed

    • Add view_data keyword argument to Inertia.render() method allowing to pass context to django template and not to Inertia view by @muarachmann in https://github.com/girardinsamuel/django-inertia/pull/5
    • A new parameter INERTIA_PAGE_CONTEXT has been added which default to __page to define the context template variable used to pass data from backend to frontend.

    New Contributors

    • @muarachmann made their first contribution in https://github.com/girardinsamuel/django-inertia/pull/5

    Full Changelog: https://github.com/girardinsamuel/django-inertia/compare/v1.1.0...v1.2.0

    Source code(tar.gz)
    Source code(zip)
  • v1.1.0(Feb 17, 2022)

  • v1.0.1(Feb 11, 2022)

    Fixed

    • Fix default sharing of errors and success messages. They are now removed after being added to the response, so that they are really non persistent flash messages.

    Full Changelog: https://github.com/girardinsamuel/django-inertia/commits/v1.0.1

    Source code(tar.gz)
    Source code(zip)
Owner
Samuel Girardin
Full-Stack Engineer (Python, Vue.js)
Samuel Girardin
Automatically deletes old file for FileField and ImageField. It also deletes files on models instance deletion.

Django Cleanup Features The django-cleanup app automatically deletes files for FileField, ImageField and subclasses. When a FileField's value is chang

Ilya Shalyapin 838 Dec 30, 2022
Simple API written in Python using FastAPI to store and retrieve Books and Authors.

Simple API made with Python FastAPI WIP: Deploy in AWS with Terraform Simple API written in Python using FastAPI to store and retrieve Books and Autho

Caio Delgado 9 Oct 26, 2022
Pinax is an open-source platform built on the Django Web Framework.

Symposion Pinax Pinax is an open-source platform built on the Django Web Framework. It is an ecosystem of reusable Django apps, themes, and starter pr

Pinax Project 295 Mar 20, 2022
Realworld - Realworld using Django and HTMX

Realworld - Realworld using Django and HTMX

Dan Jacob 53 Jan 05, 2023
Reusable, generic mixins for Django

django-braces Mixins for Django's class-based views. Documentation Read The Docs Installation Install from PyPI with pip: pip install django-braces Bu

Brack3t 1.9k Jan 05, 2023
Auth module for Django and GarpixCMS

Garpix Auth Auth module for Django/DRF projects. Part of GarpixCMS. Used packages: django rest framework social-auth-app-django django-rest-framework-

GARPIX CMS 18 Mar 14, 2022
A fresh approach to autocomplete implementations, specially for Django.

A fresh approach to autocomplete implementations, specially for Django. Status: v3 stable, 2.x.x stable, 1.x.x deprecated. Please DO regularely ping us with your link at #yourlabs IRC channel

YourLabs 1.6k Dec 22, 2022
Py-instant-search-redis - Source code example for how to build an instant search with redis in python

py-instant-search-redis Source code example for how to build an instant search (

Giap Le 4 Feb 17, 2022
A drop-in replacement for django's ImageField that provides a flexible, intuitive and easily-extensible interface for quickly creating new images from the one assigned to the field.

django-versatileimagefield A drop-in replacement for django's ImageField that provides a flexible, intuitive and easily-extensible interface for creat

Jonathan Ellenberger 490 Dec 13, 2022
Django channels basic chat

Django channels basic chat

Dennis Ivy 41 Dec 24, 2022
Django-Text-to-HTML-converter - The simple Text to HTML Converter using Django framework

Django-Text-to-HTML-converter This is the simple Text to HTML Converter using Dj

Nikit Singh Kanyal 6 Oct 09, 2022
RestApi With Django 3.2 And Django Rest Framework

RestApi-With-Django-3.2-And-Django-Rest-Framework Description This repository is a Software of Development with Python. Virtual Using pipenv, virtuale

Daniel Arturo Alejo Alvarez 6 Aug 02, 2022
Django With VueJS Blog App

django-blog-vue-app frontend Project setup yarn install Compiles and hot-reload

Flavien HUGS 2 Feb 04, 2022
A simple Django dev environment setup with docker for demo purposes for GalsenDev community

GalsenDEV Docker Demo This is a basic Django dev environment setup with docker and docker-compose for a GalsenDev Meetup. The main purposes was to mak

3 Jul 03, 2021
Learn Python and the Django Framework by building a e-commerce website

The Django-Ecommerce is an open-source project initiative and tutorial series built with Python and the Django Framework.

Very Academy 275 Jan 08, 2023
An app that allows you to add recipes from the dashboard made using DJango, JQuery, JScript and HTMl.

An app that allows you to add recipes from the dashboard. Then visitors filter based on different categories also each ingredient has a unique page with their related recipes.

Pablo Sagredo 1 Jan 31, 2022
Automatically reload your browser in development.

django-browser-reload Automatically reload your browser in development. Requirements Python 3.6 to 3.10 supported. Django 2.2 to 4.0 supported. Are yo

Adam Johnson 254 Jan 04, 2023
Drf-stripe-subscription - An out-of-box Django REST framework solution for payment and subscription management using Stripe

Drf-stripe-subscription - An out-of-box Django REST framework solution for payment and subscription management using Stripe

Oscar Y Chen 68 Jan 07, 2023
Utilities for implementing a modified pre-order traversal tree in django.

django-mptt Utilities for implementing Modified Preorder Tree Traversal with your Django Models and working with trees of Model instances. Project hom

2.7k Jan 01, 2023
The pytest framework makes it easy to write small tests, yet scales to support complex functional testing

The pytest framework makes it easy to write small tests, yet scales to support complex functional testing for applications and libraries. An example o

pytest-dev 9.6k Jan 06, 2023