Skip to main content

Facilitates adding Svelte frontend to Django

Project description

Django Svelte

Incorporate a Svelte frontend into a Django site with minimal impact to deployment strategy and authentication story.

Scope

This package mainly consists of a templatetag which facilitates the import of the js/css bundle created by Svelte/Rollup/Node.js into your template. For this package to be useful you will also need the Svelte/Rollup/Node.js which produces the js/css bundle; consider using the accompanying project django-svelte-template as a starting point for your Svelte frontend. It has been modified to work easily alongside this package. If you run into any problems see the django-svelte-demo for an example of these two projects working together.

Installation

Install the package:

pip install django-svelte

Add to INSTALLED_APPS:

INSTALLED_APPS = (
    ...
    "django_svelte",
    ...
)

Tell Django where your Svelte js/css bundles will be found (this guide assumes that you place your svelte directory beside your django project directory):

STATICFILES_DIRS = [
    BASE_DIR.parent / "svelte" / "public" / "build",
]

Usage

To use a Svelte component within your Django template load the django_svelte templatetag library and use the display_svelte templatetag:

{% load django_svelte %}

...

{% display_svelte "MySpecialComponent.svelte" %}

You can optionally pass some context (specifically a dict) to the component:

{% display_svelte "MySpecialComponent.svelte" component_props %}

What about the Svelte!?

The Svelte side of things is dealt with in the django-svelte-template repo which you can use as a starting point for your Svelte projects (using npx degit thismatters/django-svelte-template svelte). It is configured to output js/css bundles for several different components, but you'll have to do some setup so be sure to read the README.

Devops concerns

So, this isn't magic. For this to work you will need to have Node.js somewhere in the mix. Fortunately, you won't need Node.js running in your production environment, but you will need it somewhere in your CI pipeline and probably in your dev environment. For a practical example of what this might look like for a production environment see django-svelte-demo.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-svelte-0.1.3.tar.gz (2.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_svelte-0.1.3-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file django-svelte-0.1.3.tar.gz.

File metadata

  • Download URL: django-svelte-0.1.3.tar.gz
  • Upload date:
  • Size: 2.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for django-svelte-0.1.3.tar.gz
Algorithm Hash digest
SHA256 cb18551bd986576175fc91b49bccc366594443f04816443cd833290bb38c6298
MD5 cb10e3158bebe5d498e60fdb2a139e23
BLAKE2b-256 a222e3339bacf4b35ebf991281c7708741d29842c9ec42b3b14e5a1b59b1d196

See more details on using hashes here.

File details

Details for the file django_svelte-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: django_svelte-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for django_svelte-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c4d3bfc0dbabe2f530b7b09df3e132c9a61b9302e8e39dd7fcb2f19a930eb748
MD5 0f517bdf424eba3f82d190fe8de9049d
BLAKE2b-256 a40e460ed1cce843b2745de2fdc3a758a4c6fe3d38563b1d094809c3a8812bd0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page