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
Django API without Django REST framework.

Django API without DRF This is a API project made with Django, and without Django REST framework. This project was done with: Python 3.9.8 Django 3.2.

Regis Santos 3 Jan 19, 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
Simple tagging for django

django-taggit This is a Jazzband project. By contributing you agree to abide by the Contributor Code of Conduct and follow the guidelines. django-tagg

Jazzband 3k Jan 02, 2023
ProjectManagementWebsite - Project management website for CMSC495 built using the Django stack

ProjectManagementWebsite A minimal project management website for CMSC495 built

Justin 1 May 23, 2022
A Django web application that allows you to be in the loop about everything happening in your neighborhood.

A Django web application that allows you to be in the loop about everything happening in your neighborhood. From contact information of different handyman to meeting announcements or even alerts.

Kennedy Ngugi Mwaura 3 Dec 11, 2022
Cookiecutter Django is a framework for jumpstarting production-ready Django projects quickly.

Cookiecutter Django Powered by Cookiecutter, Cookiecutter Django is a framework for jumpstarting production-ready Django projects quickly. Documentati

Daniel Feldroy 10k Dec 31, 2022
Chatbot for ordering and tracking a Pizza.

Pizza Chatbot To start the app, follow the below steps: Clone the repo using the below command: git clone Shreya Shah 1 Jul 15, 2021

Django web apps for managing schedules.

skdue Description Skdue is a web application that makes your life easier by helping you manage your schedule. With the ability which allows you to cre

Patkamon_Awai 1 Jun 30, 2022
Application made in Django to generate random passwords as based on certain criteria .

PASSWORD GENERATOR Welcome to Password Generator About The App Password Generator is an Open Source project brought to you by Iot Lab,KIIT and it brin

IoT Lab KIIT 3 Oct 21, 2021
Rosetta is a Django application that eases the translation process of your Django projects

Rosetta Rosetta is a Django application that facilitates the translation process of your Django projects. Because it doesn't export any models, Rosett

Marco Bonetti 909 Dec 26, 2022
django-reversion is an extension to the Django web framework that provides version control for model instances.

django-reversion django-reversion is an extension to the Django web framework that provides version control for model instances. Requirements Python 3

Dave Hall 2.8k Jan 02, 2023
Djang Referral System

Djang Referral System About | Features | Technologies | Requirements | Starting | License | Author 🎯 About I created django referral system and I wan

Alex Kotov 5 Oct 25, 2022
Simpliest django(uvicorn)+postgresql+nginx docker-compose (ready for production and dev)

simpliest django(uvicorn)+postgresql+nginx docker-compose (ready for production and dev) To run in production: docker-compose up -d Site available on

Artyom Lisovskii 1 Dec 16, 2021
Location field and widget for Django. It supports Google Maps, OpenStreetMap and Mapbox

django-location-field Let users pick locations using a map widget and store its latitude and longitude. Stable version: django-location-field==2.1.0 D

Caio Ariede 481 Dec 29, 2022
xsendfile etc wrapper

Django Sendfile This is a wrapper around web-server specific methods for sending files to web clients. This is useful when Django needs to check permi

John Montgomery 476 Dec 01, 2022
A set of high-level abstractions for Django forms

django-formtools Django's "formtools" is a set of high-level abstractions for Django forms. Currently for form previews and multi-step forms. This cod

Jazzband 621 Dec 30, 2022
A GitHub Action for checking Django migrations

🔍 Django migrations checker A GitHub Action for checking Django migrations About This repository contains a Github Action that checks Django migratio

Oda 5 Nov 15, 2022
Python port of Google's libphonenumber

phonenumbers Python Library This is a Python port of Google's libphonenumber library It supports Python 2.5-2.7 and Python 3.x (in the same codebase,

David Drysdale 3.1k Jan 08, 2023
Exemplo de biblioteca com Django

Bookstore Exemplo de biblioteca feito com Django. Este projeto foi feito com: Python 3.9.7 Django 3.2.8 Django Rest Framework 3.12.4 Bootstrap 4.0 Vue

Regis Santos 1 Oct 28, 2021
Bringing together django, django rest framework, and htmx

This is Just an Idea There is no code, this README just represents an idea for a minimal library that, as of now, does not exist. django-htmx-rest A l

Jack DeVries 5 Nov 24, 2022