script tag with additional attributes for django.forms.Media
Project description
Usage
Use this to insert a script tag via forms.Media containing additional attributes (such as id and data-* for CSP-compatible data injection.):
media.add_js([ JS('asset.js', { 'id': 'asset-script', 'data-answer': '"42"', }), ])
The rendered media tag (via {{ media.js }} or {{ media }} will now contain a script tag as follows, without line breaks:
<script type="text/javascript" src="/static/asset.js" data-answer=""42"" id="asset-script"></script>
The attributes are automatically escaped. The data attributes may now be accessed inside asset.js:
var answer = document.querySelector('#asset-script').dataset.answer;
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
django-js-asset-0.1.0.tar.gz
(3.5 kB
view hashes)
Built Distribution
Close
Hashes for django_js_asset-0.1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a067819271e3df5bc4936e1c602dd1e3a8b3d3c634ee584963304ebeea2392f0 |
|
MD5 | 900293b55929277d7c124d28e34c2b88 |
|
BLAKE2b-256 | f2d93f71b7ab43b8a12527738637c58722530685e25a7580194c84d29cf24556 |