All Projects → zodman → inertia-django

zodman / inertia-django

Licence: Unlicense license
django connector for inertia

Programming Languages

python
139335 projects - #7 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to inertia-django

lovelace-light-soft-ui-theme
🎨 Home Assistant soft UI light theme, with help from @JuanMTech, @thomasloven, and @N-l1.
Stars: ✭ 59 (-34.44%)
Mutual labels:  hacktoberfest2020
LocationTracker-WorkManager
Get Location Updates on 15 minutes interval via WorkManager.
Stars: ✭ 70 (-22.22%)
Mutual labels:  hacktoberfest2020
HacktoberFest2020
🤗Feel free to submit a PR💻 to have it merged and get a free Hacktoberfest tee👕 from Github🔮. Updated as per new guidelines✔️
Stars: ✭ 22 (-75.56%)
Mutual labels:  hacktoberfest2020
javascript-jokes
PR your joke if you know good ( or horrible ) js joke . I will post it on coding valley's insta page.
Stars: ✭ 66 (-26.67%)
Mutual labels:  hacktoberfest2020
generate-express
Express generator CLI with es6+ support and your choice of database config
Stars: ✭ 17 (-81.11%)
Mutual labels:  hacktoberfest2020
synchly
Automate database backups with customizable recurring schedules.
Stars: ✭ 27 (-70%)
Mutual labels:  hacktoberfest2020
SquirrelJME
SquirrelJME is a Java ME 8 Virtual Machine for embedded and Internet of Things devices. It has the ultimate goal of being 99.9% compatible with the Java ME standard.
Stars: ✭ 148 (+64.44%)
Mutual labels:  hacktoberfest2020
Radar.Adr
The Action-Domain-Responder core for Radar.
Stars: ✭ 53 (-41.11%)
Mutual labels:  hacktoberfest2020
creativecommons.github.io-source
Source files for CC Open Source website
Stars: ✭ 51 (-43.33%)
Mutual labels:  hacktoberfest2020
asscan
Automated Subnet Scanner
Stars: ✭ 25 (-72.22%)
Mutual labels:  hacktoberfest2020
RTU-DigitalLibrary
This is an opensource repository by Rajasthan Technical University for all engineering students and the folders contain codes written in different programming languages. You can even add a folder of say, Javascript or Php, if your language isn't listed. Happy coding everyone.
Stars: ✭ 19 (-78.89%)
Mutual labels:  hacktoberfest2020
data-structures-algorithms-interviews
👨‍💻 Repo contains my solutions to coding interview problems on various platforms. Will later convert into a React based web app for personal revision.
Stars: ✭ 16 (-82.22%)
Mutual labels:  hacktoberfest2020
ebisp
Embedded Lisp
Stars: ✭ 46 (-48.89%)
Mutual labels:  hacktoberfest2020
2cca
2-cent Certification Authority
Stars: ✭ 27 (-70%)
Mutual labels:  hacktoberfest2020
SparkAR-Creators
The right place for SparkAR creators from around the globe. Exchange resources on SparkAR, assets, patches and scripts to make your favourite filters for Instagram and Facebook. Create your spark here!
Stars: ✭ 24 (-73.33%)
Mutual labels:  hacktoberfest2020
robotframework-seleniumtestability
Extension for SeleniumLibrary that provides manual and automatic waiting for asyncronous events like fetch, xhr, etc.
Stars: ✭ 34 (-62.22%)
Mutual labels:  hacktoberfest2020
live deck
A Real-Time Presentation Application Powered by Phoenix LiveView
Stars: ✭ 71 (-21.11%)
Mutual labels:  hacktoberfest2020
neu ui
Prototype and build projects faster using Neu UI - an open source React component library designed to neumorphic style. Built using React, Styled Components, Jest and Storybook.
Stars: ✭ 23 (-74.44%)
Mutual labels:  hacktoberfest2020
Igloo
Official GitHub repo for Igloo - The private social media
Stars: ✭ 17 (-81.11%)
Mutual labels:  hacktoberfest2020
IOSD-UIETKUK-HacktoberFest-Meetup-2019
This repository for IOSD HacktoberFest 2020
Stars: ✭ 17 (-81.11%)
Mutual labels:  hacktoberfest2020

inertia-django conector

Python package Coverage Status

TL;DR:

inertia-django connetor gives you the ability to replace 'classic' templates with Vue / React / Svelte components.

  • SPA user experience with MPA style development flow.
  • No need for clientside routing, just use urls.py.
  • No need for API endpoints, just pass data directly to the props of the client-side component.

based on inertia-laravel.

demo project available in this repo: https://github.com/zodman/django-inertia-demo

more on inertia: https://inertiajs.com

Usage

render_inertia function

The easiest way to render a Vue component with inertia-django is to use the render_inertia function.
Note: You must have an Index.vue component in your project.

from inertia import render_inertia

def index(request):
    # for function views just use the render_inertia function
    return render_inertia(
        request,
        'Index',
        props={'title': 'My inertia-django page'},
        template_name='index.html'
    )

Server-side setup

Install dependencies

pip install inertia-django django-js-routes

Root Template

{# templates/base.html #}
{% load js_routes_tags %}<!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" />
    {% js_routes %}
    <script src="{{ STATIC_URL}}dist/app.js" defer></script>
    <link href="{{ STATIC_URL}}dist/app.css" rel="stylesheet" />
            
  </head>
  <body class="font-sans leading-none text-gray-700 antialiased">
    {{ page|json_script:"page" }}
    <div id="app">
    </div>
  </body>
</html>

Creating responses

from inertia.views import render_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 render_inertia(request, "Event/Show", props)

We strongly recommend to use marshmallow since it has a serializer, validation and fully compatible with django.

Client-side setup

Install dependencies

npm install @inertiajs/inertia @inertiajs/inertia-vue 
# extra deps
npm install parcel-bundler

Initialize app

import { InertiaApp } from '@inertiajs/inertia-vue'
import Vue from 'vue'
Vue.use(InertiaApp);

const app = document.getElementById('app');
// we are getting the initialPage from a rendered json_script
const page = JSON.parse(document.getElementById("page").textContent);

import Index from "./Pages/Index";
import Contacts from "./Pages/Contacts";
import Organization from "./Pages/Organizations";
import ContactEdit from "./Pages/Contacts.Edit";

const pages = {
  'Login': Login,
  'Index': Index,
  'Contacts': Contacts,
  'Contacts.Edit': ContactEdit,
}

new Vue({
  render: h => h(InertiaApp, {
    props: {
      initialPage: page,
      resolveComponent: (name) => {
        console.log("resolveComponent ", name)
        return pages[name];
      },
    },
  }),
}).$mount(app)

TODO: add why not use resolveComponent dynamic.

Routing

Generating URLs

For the part of the urls the same functionality as laravel or ziggy is

django-js-routes https://pypi.org/project/django-js-routes/

TODO: explain how inertia/middleware.py works

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].