Django template tag to load static files inline with your template.
Project description
django-staticinline
Similiar to Django’s native static templatetag, but this includes the file directly in the template, rather than a link to it.
Example:
{% load staticinline %}
<style type="text/css">{% staticinline "myfile.css" %}</style>
<script>{% staticinline "myfile.js" %}</script>
Becomes:
<style type="text/css">body{ color: red; }</style>
<script>alert("Hello World");</script>
If the file does not exist, and DEBUG is False, an empty string is returned and a error logfile is set. In case DEBUG is True, a ValueError is raised.
Installation
This Django app is compatible with Django 1.8 → 2.0, Python 2.7 all versions of Python 3.x.
Install the app with pip and add staticinline.apps.StaticInlineAppConfig to your installed apps in your settings.py:
pip install django-staticinline
INSTALLED_APPS = [
# ...
'staticinline.apps.StaticInlineAppConfig',
]
Encoder and Customization
You can automatically convert the file with the encode argument. django-staticinline ships with two encoders: base64 that transforms the file content to a base64 encoded string, and data that transforms the content into a data URI for use in CSS url() and HTML src="" attributes.
base64 encoder
{% load staticinline %}
{% staticinline "mykey.pem" encode="base64" %}'
Becomes:
LS0tIFN1cGVyIFByaXZhdGUgS2V5IC0tLQo=
data encoder
{% load staticinline %}
ul.checklist li.complete {
background: url('{% staticinline "icons/check.png" encode="data" %}');
}
Becomes:
ul.checklist li.complete {
background: url('data:image/png;base64,iVBORw0KG\
goAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD//\
/+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83ND\
DeNGe4Ug9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQ\
mCC');
}
Custom filters
You can add custom filters by setting them in a custom AppConfig. See the default AppConfig in staticinline/apps.py for further documentation. The test suite also uses a custom AppConfig, which will help you to understand the setup. See staticinline/tests/testapp/apps.py for it.
Changelog
v1.1 (2018-08-09)
Support for custom data encoders to modify file content on the fly.
Adds data and base64 encoders, both convert data into base64.
v1.0 (2018-04-29)
Initial release.
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
Built Distribution
File details
Details for the file django-staticinline-1.1.tar.gz
.
File metadata
- Download URL: django-staticinline-1.1.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8844be14d1d91dbc96cc36fcdc4355f00dee79eb84530994607fff8cfef0e48f |
|
MD5 | 8b9ca98f9e812502a37877c2c93975fa |
|
BLAKE2b-256 | 6ee9925ba1c8bd2232bcec15721051d6f01075876e72b07e75a8a68bd0011d6b |
File details
Details for the file django_staticinline-1.1-py2.py3-none-any.whl
.
File metadata
- Download URL: django_staticinline-1.1-py2.py3-none-any.whl
- Upload date:
- Size: 12.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60c07b2066c53df868373e30198ab10d8572077d4eb268337a77036f705bdb4f |
|
MD5 | ec39410d1d1ebedb12a4daa2a82db062 |
|
BLAKE2b-256 | 81dd1a2f1fece95d3ee87b424def629b5c0179ecb2ffc006b4291dc6f1a1749b |