Skip to main content

Django Faucet Pipeline

Build Status PyPI version

django-faucet-pipeline integrates faucet-pipeline with Django. It allows you to transparently reference assets created by faucet-pipeline in Django templates and operate on them using the django.contrib.staticfiles app.

Usage

Configuring Django and faucet-pipeline

To start using faucet-pipeline in Django, you need to make sure that both the staticfiles and the django_faucet_pipeline app are mentioned in the INSTALLED_APPS section of settings.py:

INSTALLED_APPS = [
    …,
    'django.contrib.staticfiles',
    'django_faucet_pipeline',
]

faucet-pipeline needs to be configured to write a manifest.json file for integrating with Django. By default, django-faucet-pipeline will look for this file in the BASE_DIR of the Django project (as specified by settings.py). You can customise the search path using FAUCET_PIPELINE_MANIFEST setting.

The manifest configuration needs to align with the Django configuration in two respects: The STATIC_URL in settings by needs to be the same as the baseURI in the manifest config. Also, all assets need to be output into the webRoot, which also needs to be configured as one of the STATICFILES_DIRS in Django. For example, if you were to have the following configuration in Django:

BASE_DIR = Path(__file__).resolve().parent.parent
STATIC_URL = '/static/'
STATICFILES_DIRS = [
    BASE_DIR / "dist/"
]

A compatible faucet.config.js might look as follows:

module.exports = {
    js: {
        input: 'app/index.js',
        output: 'dist/bundle.js'
    },
    manifest: {
        target: "./manifest.json",
        key: "short",
        baseURI: "/static/",
        webRoot: "./dist"
    }
};

django-faucet-pipeline will emit an error message if it cannot read the manifest file, but it will not check whether your webRoot and and STATICFILES_DIRS configuration is correct.

Referencing assets

In order to reference an asset, you simply use the static_faucet template tag from the faucet_pipeline library. This behaves similarly to the "standard" static tag, but automatically expands the canonical name of the asset to the current (potentially fingerprinted) name.

{% load static_faucet from faucet_pipeline %}
<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Hello World</title>
  </head>
  <body> 
  <script src="{% static_faucet "bundle.js" %}" type="text/javascript"></script>
  </body>
</html>

Debug vs. Production

The behaviour of django-faucet-pipeline will change depending on whether the Django settings DEBUG is set to true or not. If debug mode is enabled, the manifest file will be re-read when ever a template is rendered. In production, you should have DEBUG set to False, in which case manifest.json will be read once on first access and then cached indefinitely.

Release files for django-faucet-pipeline 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-faucet-pipeline 1.0.0
File Size Uploaded
django-faucet-pipeline-1.0.0.tar.gz 7.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-faucet-pipeline 1.0.0
File Interpreter ABI Platform
django_faucet_pipeline-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.7 kB

Release files / django-faucet-pipeline-1.0.0.tar.gz

Download URL django-faucet-pipeline-1.0.0.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
656cea9b6541e3fcabc819044d2c653635299ba623bfdee35edc00a8bb0cb96c
BLAKE2b-256 checksum
How to use checksums
e32245050ab143c9883b7b08309df7c51bbc493f097e3f1bdae787b0bceee471
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.7.9

Release files / django_faucet_pipeline-1.0.0-py3-none-any.whl

Download URL django_faucet_pipeline-1.0.0-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1c2d4acfd9009142b9daa1d45653359fae14adfdcea8bce8d2759212292223b7
BLAKE2b-256 checksum
How to use checksums
be742ebd56423f11a246f1bb815da823c69990c20796bc86c667cb433d0c7458
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.7.9

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page