Skip to main content

Django template tag to load static files inline with your template.

Project description


Similiar to Django’s native static templatetag, but this includes the file directly in the template, rather than a link to it.


{% load staticinline %}

<style type="text/css">{% staticinline "myfile.css" %}</style>
<script>{% staticinline "myfile.js" %}</script>


<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.


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

pip install django-staticinline
    # ...

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" %}'



data encoder

{% load staticinline %}
ul.checklist li.complete {
    background: url('{% staticinline "icons/check.png" encode="data" %}');


ul.checklist li.complete {
    background: url('data:image/png;base64,iVBORw0KG\

Custom filters

You can add custom filters by setting them in a custom AppConfig. See the default AppConfig in staticinline/ for further documentation. The test suite also uses a custom AppConfig, which will help you to understand the setup. See staticinline/tests/testapp/ for it.


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.

Files for django-staticinline, version 1.1
Filename, size File type Python version Upload date Hashes
Filename, size django_staticinline-1.1-py2.py3-none-any.whl (12.1 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size django-staticinline-1.1.tar.gz (11.2 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page