Django template tag to load static files inline with your template.
Project description
django-staticinline
Works similar to Django’s static templatetag, but this one includes the file directly in the template, rather than a link to it.
You can additionally post-process the file content using custom ‘encoder’.
Compatibility Matrix:
Py/Dj |
3.8 |
3.9 |
3.10 |
3.11 |
---|---|---|---|---|
2.2 (LTS) |
✓ |
✓ |
✓ |
✓ |
3.2 (LTS) |
✓ |
✓ |
✓ |
✓ |
4.0 |
✓ |
✓ |
✓ |
✓ |
4.1 |
✓ |
✓ |
✓ |
✓ |
4.2 (LTS) |
✓ |
✓ |
✓ |
✓ |
Quickstart
Put the StaticInlineAppConfig along your apps.
INSTALLED_APPS = [ # ... 'staticinline.apps.StaticInlineAppConfig', ]
Load the template tag and pass a filename as you’d do with a static template tag. You can also post-process the file content. In the example below we encode the content of the mykey.pem file with base64. Several encoders are already built-in, see the Encoder docs.
{% load staticinline %} <style type="text/css">{% staticinline "myfile.css" %}</style> My base64 encoded Key: {% staticinline "mykey.pem" encode="base64" cache=True %}
Enjoy the result:
<style type="text/css">body{ color: red; }</style> My base64 encoded Key: LS0tIFN1cGVyIFByaXZhdGUgS2V5IC0tLQo=
Changelog
v1.4
Django 3.2 to 4.2 compatibility and tests.
Python 3.8 to 3.11 compatibility and tests.
v1.3 (2018-08-15)
Added cache and cache_timeout templatetag arguments to store rendered values in cache.
Added data_response AppConfig method to globally override the template tag response.
v1.2 (2018-08-14)
Added support for Django 2.1 and Python 3.7.
Added proper documentation.
Added sri (Subresource Integrity) encoder to generate a sha256 for a given file.
v1.1 (2018-08-09)
Added support for custom data encoders to modify file content on the fly.
Added 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.4.tar.gz
.
File metadata
- Download URL: django-staticinline-1.4.tar.gz
- Upload date:
- Size: 29.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbfe9c759e90d20fbcb8c8a9dcb3dea8481fb40b93033b8a66d8a8badd5d0b11 |
|
MD5 | 443eb42ec308ed8eeacf353282df89c4 |
|
BLAKE2b-256 | 467ca6c0b9b4851f4039d2e608a8dcac3c40774525383e30e23f7123046ceae9 |
File details
Details for the file django_staticinline-1.4-py2.py3-none-any.whl
.
File metadata
- Download URL: django_staticinline-1.4-py2.py3-none-any.whl
- Upload date:
- Size: 13.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d80bc777928a20a7cf825c5af1c0a2c5e066256648ad26da830dc70ba26a73cd |
|
MD5 | bfaed9a93712f7e8d111a99b55526d7d |
|
BLAKE2b-256 | dd6510fe244aba9982a15618ae7a8586bd9ce748ac3f4942ce7b5b088a51c38a |