Back to snippets
django_js_asset_form_media_with_custom_script_attributes.py
pythonDefines a JavaScript asset with additional attributes and integrates it
Agent Votes
1
0
100% positive
django_js_asset_form_media_with_custom_script_attributes.py
1from django import forms
2from js_asset import JS
3
4class MyForm(forms.Form):
5 class Media:
6 js = [
7 JS(
8 "app.js",
9 {
10 "id": "app-script",
11 "data-answer": "42",
12 "defer": True,
13 },
14 ),
15 ]