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
Thumbnails for Django

Thumbnails for Django. Features at a glance Support for Django 2.2, 3.0 and 3.1 following the Django supported versions policy Python 3 support Storag

Jazzband 1.6k Jan 03, 2023
Django Pickled Model

Django Pickled Model Django pickled model provides you a model with dynamic data types. a field can store any value in any type. You can store Integer

Amir 3 Sep 14, 2022
A Django/Python web app that functions as a digital diary

My Django Diary Full-stack web application that functions as a digital diary using Django, Python, SQLite, HTML & CSS. Things I learned during this pr

1 Sep 30, 2022
Zendesk Assignment - Django Based Ticket Viewer

Zendesk-Coding-Challenge Django Based Ticket Viewer The assignment has been made using Django. Important methods have been scripted in views.py. Excep

Akash Sampurnanand Pandey 0 Dec 23, 2021
Ugly single sign-on for django projects only

django-usso Ugly single sign-on for django projects only. Do you have many django apps with different users? Do you want to use only one of those apps

Erwin Feser 1 Mar 01, 2022
Django Federated Login provides an authentication bridge between Django projects and OpenID-enabled identity providers.

Django Federated Login Django Federated Login provides an authentication bridge between Django projects and OpenID-enabled identity providers. The bri

Bouke Haarsma 18 Dec 29, 2020
Automated image processing for Django. Currently v4.0

ImageKit is a Django app for processing images. Need a thumbnail? A black-and-white version of a user-uploaded image? ImageKit will make them for you.

Matthew Dapena-Tretter 2.1k Jan 04, 2023
demo project for django channels tutorial

django_channels_chat_official_tutorial demo project for django channels tutorial code from tutorial page: https://channels.readthedocs.io/en/stable/tu

lightsong 1 Oct 22, 2021
Yummy Django API, it's the exclusive API used for the e-yummy-ke vue web app

Yummy Django API, it's the exclusive API used for the e-yummy-ke vue web app

Am.Chris_KE 1 Feb 14, 2022
A Minimalistic Modern Django Boilerplate

A Minimalistic Modern Django Boilerplate This boilerplate is mainly for educational purposes. It is meant to be cloned as a starter code for future tu

Jonathan Adly 21 Nov 02, 2022
Highlight the keywords of a page if a visitor is coming from a search engine.

Django-SEKH Django Search Engine Keywords Highlighter, is a middleware for Django providing the capacities to highlight the user's search keywords if

Julien Fache 24 Oct 08, 2021
django-idom allows Django to integrate with IDOM

django-idom allows Django to integrate with IDOM, a package inspired by ReactJS for creating responsive web interfaces in pure Python.

113 Jan 04, 2023
A Django web application to receive, virus check and validate transfers of digital archival records, and allow archivists to appraise and accession those records.

Aurora Aurora is a Django web application that can receive, virus check and validate transfers of digital archival records, and allows archivists to a

Rockefeller Archive Center 20 Aug 30, 2022
Django server-side adapter for Inertia.js

django-inertia Django server-side new adapter for Inertia.js. Getting Started Install the package pip install django-inertia Configure your project A

Samuel Girardin 14 Sep 16, 2022
GameStop clone with Django

GameStop clone with Django This is my side project with GameStop clone Author: HackerApe GitHub Profile: View Profile LinkedIn Profile: View Profile

Dmitriy Shin 2 Dec 26, 2021
PEP-484 type hints bindings for the Django web framework

mypy-django Type stubs to use the mypy static type-checker with your Django projects This project includes the PEP-484 compatible "type stubs" for Dja

Machinalis 223 Jun 17, 2022
This is a Django app that uses numerous Google APIs such as reCAPTURE, maps and waypoints

Django project that uses Googles APIs to auto populate fields, display maps and routes for multiple waypoints

Bobby Stearman 57 Dec 03, 2022
Django/Jinja template indenter

DjHTML A pure-Python Django/Jinja template indenter without dependencies. DjHTML is a fully automatic template indenter that works with mixed HTML/CSS

Return to the Source 378 Jan 01, 2023
🗂️ 🔍 Geospatial Data Management and Search API - Django Apps

Geospatial Data API in Django Resonant GeoData (RGD) is a series of Django applications well suited for cataloging and searching annotated geospatial

Resonant GeoData 53 Nov 01, 2022
Full featured redis cache backend for Django.

Redis cache backend for Django This is a Jazzband project. By contributing you agree to abide by the Contributor Code of Conduct and follow the guidel

Jazzband 2.5k Jan 03, 2023