About Rendering a Python Dictionary as JSON
Create a simple template filter to_json
to convert Python lists and dictionaries to JSON in your templates:
1 2 3 4 5 6 7 8 9 10 11 |
|
Then you can use the filter for an attribute of an HTML tag
1 2 3 |
|
or a JavaScript variable:
1 2 3 4 5 |
|
Tips and Tricks Programming Development Django 4.2 Django 3.2 Django 2.2 Python 3 JavaScript HTML5
Also by me
Django Paddle Subscriptions app
For Django-based SaaS projects.
Django GDPR Cookie Consent app
For Django websites that use cookies.