django-js-asset
script tag with additional attributes for django.forms.Media
What it is and what it does
django-js-asset extends Django's forms.Media to render script, stylesheet, and JSON tags with arbitrary HTML attributes—particularly useful for Content Security Policy nonces, module types, and data attributes. It provides JS, CSS, and JSON classes that produce Django's native Script and Stylesheet objects (backported on older Django versions), ensuring proper deduplication when multiple forms and widgets contribute media to a single page. The package also handles import maps, merging them into a single script tag rendered before all other scripts so that modules can rely on them without rewriting imports.
The library is designed for Django developers who need fine-grained control over script and stylesheet rendering—especially in admin customizations, complex forms, and applications requiring CSP compliance. It bridges the gap between older Django versions and Django 5.2's native Script object support, offering a consistent API across versions. A static helper function abstracts version differences in Django's static file handling, and the Media class can merge import maps and combine assets from multiple sources (views, forms, widgets) into a single deduplicated output.
Use it for:
- Inject CSP nonces into script tags for security-conscious applications without manual template manipulation.
- Add data attributes to scripts for passing configuration from Django templates to JavaScript without global variables.
- Render import maps alongside module scripts, letting the browser resolve short module names to hashed static file URLs.
- Combine media from multiple forms and widgets while automatically deduplicating identical assets across Django versions.
- Render inline CSS and JSON blobs alongside external stylesheets and scripts in a single Media object.
- Migrate from older Django versions to 5.2 while maintaining a consistent asset API across the codebase.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Adds script, stylesheet, and JSON tags with custom attributes to Django's forms.Media, enabling CSP-compatible data injection and import map support.
Yes. The package is actively maintained, has no known vulnerabilities, and solves a real problem for Django developers who need custom script attributes or import map support. It's especially valuable if you're using CSP nonces, passing data to scripts via attributes, or managing complex form media across multiple Django versions. The low install friction and permissive license make adoption straightforward.
Install
django-js-asset on PyPI
pip
pip install django-js-assetuv
uv add django-js-assetpoetry
poetry add django-js-assetInstalling django-js-asset
Before you install
Low friction: single dependency on django, wheel-only distribution, and actively maintained with a recent release. Supports modern Python versions (3.10–3.14) and Django 4.2 and later.
License in practice
BSD-3-Clause is permissive; you may use, modify, and distribute this package freely in commercial and private projects with minimal restrictions.
Quickstart
pip install django-js-asset
from django_js_asset import JS, CSS, JSON
from django import forms
media = forms.Media(js=[
JS("script.js", {"id": "my-script", "data-config": "value"}),
])
Requires Django 4.2 or later and Python 3.10 or later.
Verify before relying
- Whether the deduplication behavior across Django 5.2–6.1 (path-only matching) versus 4.2/6.2+ (path + attributes) affects your use case.
- Support status for Django versions beyond 6.2 (fact sheet mentions 'main branch' compatibility but no explicit version ceiling).
Package facts
| License | BSD-3-Clause (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — django |
| Maintenance | actively maintained — 64 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 3,475,121/month — #2,611 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: django_js_asset-4.0.1-py3-none-any.whl
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
django-ckeditorIntegrates CKEditor 4.18.0 rich-text editing…
permissive · top 5,000 on PyPI
django-sriGenerates Subresource Integrity (SRI) hashes…
permissive · top 15,000 on PyPI
django-json-widgetProvides a rich JSON editor widget for Django's…
permissive · top 5,000 on PyPI
django-pipelinedjango-pipeline bundles and compresses CSS and…
permissive · top 15,000 on PyPI
django-jsonformProvides a user-friendly JSON editing form…
permissive · top 15,000 on PyPI
django-viteIntegrates Vite, a modern JavaScript build…
permissive · top 5,000 on PyPI
django-aceIntegrates the ACE code editor into Django…
permissive · top 15,000 on PyPI
django-compressorDjango Compressor combines, minifies, and…
permissive · top 5,000 on PyPI
django-componentsdjango-components lets you build reusable,…
permissive · top 15,000 on PyPI
django-map-widgetsProvides interactive and static map widgets for…
permissive · top 15,000 on PyPI