A Django integration for faucet-pipeline
Project description
Django Faucet Pipeline
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django-faucet-pipeline-1.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 656cea9b6541e3fcabc819044d2c653635299ba623bfdee35edc00a8bb0cb96c |
|
MD5 | a0d8026c1899518cabf6cdd3e8dd5a28 |
|
BLAKE2b-256 | e32245050ab143c9883b7b08309df7c51bbc493f097e3f1bdae787b0bceee471 |
Hashes for django_faucet_pipeline-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c2d4acfd9009142b9daa1d45653359fae14adfdcea8bce8d2759212292223b7 |
|
MD5 | 9430c128f2f55ed5849f1b679ffa84f4 |
|
BLAKE2b-256 | be742ebd56423f11a246f1bb815da823c69990c20796bc86c667cb433d0c7458 |