Skip to main content

django-simpleinliner

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.

Rationale

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.

Compatibility

The widget has been tested on all Python/Django version combinations officially supported by the Django project:

Django 4.2 5.0 5.1 5.2
Python 3.8
3.9
3.10
3.11
3.12
3.13
3.14

If you need to use django-simpleinliner with Django 3, please use a version of the package prior to 1.0.0.

Installation

$ pip install django-simpleinliner

Add simpleinliner to your INSTALLED_APPS setting.

Usage

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. Note that when using inlinegeneric no wrapper tag will be rendered – this is designed for files such as SVGs that already include all necessary markup.

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

SIMPLEINLINER_DEFAULT_TAG_ATTRIBUTES = {
    'script': {
        'type': 'text/javascript',
    },
    'style': {
        '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

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

$ pip install -e .[dev]

Run the runserver to load the test template:

$ cd example_project
$ python manage.py runserver 0.0.0.0:8000

Run the basic test suite across environments using tox:

$ tox run

Credits

Since version 0.2.5 this library bundles a lightly modified version 1.16 of the html library (in html.py), 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!

Release files for django-simpleinliner 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-simpleinliner 1.0.0
File Size Uploaded
django_simpleinliner-1.0.0.tar.gz 14.9 kB Details

Release files / django_simpleinliner-1.0.0.tar.gz

Download URL django_simpleinliner-1.0.0.tar.gz
Size 14.9 kB
Tags Source
SHA-256 checksum
How to use checksums
b22b0501b36692054ccb1f39308928393b98ae394036fdb4027a655e14ff9588
BLAKE2b-256 checksum
How to use checksums
86a3c073eac1b6feae7794929ecffea8b78ce42888088b0499ec0fb3de02d68b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release history Release notifications | RSS feed

This release

1.0.0 This release

1 release file

0.3.8

1 release file

0.3.7

1 release file

0.3.6

1 release file

0.3.5

1 release file

0.3.4

1 release file

0.3.3

1 release file

0.3.2

1 release file

0.3.0

1 release file

0.2.5

1 release file

0.2.4

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page