Skip to main content

A simple Django app for inlining static files in templates.

Project description


A simple Django app for inlining static CSS and JS files in templates. Read CSS, JS or generic files from your static directories and insert their contents into your Django templates, wrapping in appropriate HTML tags if necessary.


Provides a quick and easy way to inline an entire JS or CSS file from staticfiles into a template, wrapping it in appropriate tags. django-compressor does this but I wanted something more lightweight, and also wanted to try my hand at writing a Django extension. Some inspiration and staticfile-handling code was taken from django-inlinecss.


I've not exhaustively tested all the below combinations, however I believe this table to be accurate.

Django 1.10 1.11 2.0 2.1 2.2 3.0 3.2 3.2
Python 2.7


$ pip install django-simpleinliner

Add simpleinliner to your INSTALLED_APPS setting.


Load the app at the top of your template:

{% load simpleinliner %}

Call inlinecss, inlinejs or inlinegeneric where you want to pull in a static file:

{% inlinejs 'path/to/my.js' %}

{% inlinecss 'path/to/my.css' %}

{% inlinegeneric 'path/to/my.svg' %}

The file will be inserted into the template each time the template is rendered, keeping it up to date.

You can override the default attributes given to <script> and <style> tags generated by simpleinliner by including the following in your project settings:

    'script': {
        'charset': 'utf-8',
        'type': 'text/javascript',
    'style': {
        'charset': 'utf-8',
        'type': 'text/css',

Add or edit these as desired to change the attributes applied to these tags.

By default simpleinliner will silently fail (including an empty tag if using inlinejs or inlinecss) if the specified path doesn't exist. You can force it to raise an exception by setting SIMPLEINLINER_RAISE_EXCEPTIONS to True in your project settings.

Development Installation

If working locally on the package you can install the development tools via pip:

$ pip install -e .[dev]

To lint with flake8:

$ flake8


Since version 0.2.5 this library bundles version 1.16 of the html library (in, as that library does not correctly install itself in modern python/setuptools environments and cannot be correctly imported.

Issues, Suggestions, Contributions

...are welcome on GitHub. Thanks for your interest in simpleinliner!

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-simpleinliner, version 0.3.6
Filename, size File type Python version Upload date Hashes
Filename, size django-simpleinliner-0.3.6.tar.gz (12.2 kB) File type Source Python version None Upload date Hashes View

Supported by

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