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.):
from js_asset import JS 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;
Also, because the implementation of static differs between supported Django versions (older do not take the presence of django.contrib.staticfiles in INSTALLED_APPS into account), a js_asset.static function is provided which does the right thing automatically.
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
Built Distribution
Hashes for django_js_asset-0.1.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0dd2c5f64f2b24eb8a7270a6a59cb914a03f205335bd0eb6207bf61cf7410828 |
|
MD5 | bd98771e4aa321737f3594d7816c3a5c |
|
BLAKE2b-256 | 206f462444435476d2015cf54dd6eaa08447a566b586ff6e7fca19c2d4639e86 |