Skip to main content

Simple client-side dependency management for your django project.

Project description

Django client-side dependencies app

PyPI Version Tests

Manage client-side JS / CSS dependencies for your django project.

OVERVIEW:

  • Maintain client-side dependencies in one place (i.e., not scattered in templates).
  • Provides testable, executable client-side app dependencies set.
  • Template tags used to pull JS / CSS dependencies into templates.
  • Local static resources and/or from CDN.
  • Use any client-side build tools or none - demo app uses npm as JS package manager and build tool.
  • conditional dependencies for different build environments

Dependencies:

  • python 3
  • django

Quick start

  • pip install https://github.com/powderflask/django-client-side.git
  1. Add client_side to INSTALLED_APPS

    INSTALLED_APPS = [
        ...
        'client_side',
    ]
    
  2. define client-side dependency set (see tests.dependencies for example)

  3. in settings.py, configure CLIENT_SIDE_DEPENDENCIES setting:

    CLIENT_SIDE_DEPENDENCIES = 'myproject.client_side.dependencies.DEPENDENCIES'  # dotted-path to your dependency sets
    

    (may be a dotted-path to a DependencySets object or specify the DependencySets object directly in settings.)

  4. Use {% stylesheet <name> %} and {% javascript <name> %} in your templates to pull in sets of dependencies

  5. Update your client-side dependency sets any time without ever touching your templates!

Guide

Define Client-Side Components

 from client_side.component import Component, DependencySets, Script, Stylesheet

Define a Component for each dependency, with zero or more Script elemenets and/or zero or more Stylesheet elements:

component = Component(
    Script(url="https://example.com/component.js", sri="sha384-js-sri-here"),
    Stylesheet(url="https://example.com/component.css", sri="sha384-css-sri-here"),
)

Swap components for different environments, pass static=True for dependencies loaded from static files:

lib_common = Component(
    Script(url="lib/common.js" if settings.DEBUG else "lib/common.min.js", static=True),
    Stylesheet(
        url="lib/common.css" if settings.DEBUG else "lib/common.min.css", static=True
    ),
)

Group Components into Logical Dependency Sets

Define one or more DependencySets with logical component groups:

DEPENDENCIES = DependencySets(
    core=(component, lib_common,),
    debug=(debug_toolbar, hijack), 
)

Include DependencySets in Templates

{% load dependency_tags %}
...
      {% stylesheet 'core' %}
...
      {% javascript 'core' %}
      {% if debug %}
        {% javascript 'debug' %}
      {% endif %}  

Acknowledgments

Special thanks to BC Hydro, Chartwell, and all Contributors

For Developers

  • > pip install -r reqirements_dev.txt

Tests

  • > pytest
  • > tox

Code Style

  • > isort
  • > black
  • > flake8

Versioning

Build / Deploy Automation

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-client-side-0.3.1.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

django_client_side-0.3.1-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file django-client-side-0.3.1.tar.gz.

File metadata

  • Download URL: django-client-side-0.3.1.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for django-client-side-0.3.1.tar.gz
Algorithm Hash digest
SHA256 fc40876799592a6d7068c765328faf558271e253242f7d96902bf886c2c5475a
MD5 1bb9a2c33e0d5080c27266a9b444f3a4
BLAKE2b-256 212f5aa09067f9ff9bbbeb69c834ed27e47a70217298e0ee33f427d8647ceb2b

See more details on using hashes here.

File details

Details for the file django_client_side-0.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_client_side-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0508a69b092a14603fc1efff1e5cfe3933e2fc39a17fc87253aec1174a82263e
MD5 58669ee160f71736bd7d249ef7ebe1ae
BLAKE2b-256 a825cde21ca8aa41ac51e47c8f1896705e33c0c98fdc552d41de38d665a5a095

See more details on using hashes here.

Supported by

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