A template for Django that uses InertiaJS, Svelte, and TailwindCSS. Preconfigured for HMR and SSR.
The master branch contains the template for use in the instructions, and a runnable demo is in the testing branch.
If you're particular about how the template sets things up, you can see the full comparison here.
This template builds off of these two templates
npm create vite@latest
django-vite
, inertia-django
, django-js-routes
, and example_app to appsweb/dist
as a staticfile dirpages
directory to src
with Example.svelte
main.js
following InertiaJS Svelte docsssr.js
following InertiaJS Svelte docsSetup a virtual environment/Poetry/whatever and install django
, inertia-django
,
django-vite
, and django-js-routes
.
Run
django-admin startproject --template https://github.com/pmdevita/django-svelte-template/archive/master.zip my_django_project .
CD into web
and run npm i
Run both Django and Vite (python manage.py runserver
and npm run dev
) and visit Django's URL http://127.0.0.1:8000
SSR support is still unpolished in inertia-django, but it is possible to get running. You technically can
use SSR and HMR together, but you'll have to rebuild the SSR server on every change. Because of this,
you might just want to use static builds of your site (npm run build
).
First, we need to build the SSR server application by running npm run build-ssr
. You can find some
more info about Vite SSR here. The port can be changed
in web/src/ssr.js
.
web/vite.config.js
, set hydratable
to true
.your_django_project/settings.py
, set INERTIA_SSR_ENABLED
to True (and if you are just using
static builds, set DJANGO_VITE_DEV_MODE
to False)web
, node dist-ssr/ssr.js
)A few things might be nice to have housed in this project as well.
npm create vite@latest
with Svelte TypeScript option)Since we try to maintain both a working example and a template on the same git history, there's a bit of a process to updating this. Updates fall into three categories
Each one belongs to a separate branch, which are chained by rebasing from
django-svelte-base
-> testing
-> master