Ersetzen Sie den Wert des Jinja -Vorlagenwerts im Wörterbuch Python

import re
from jinja2 import Template

template = '{"text": {{text}}, "peripherals": {{peripherals}}}'
# Use regular expressions to identify the variables
template = re.sub(r"({{)(\w*)(}})", r'"\1\2\3"', template)

jT = Template(template)

params = {'text': 'some_text', 'peripherals': 'mouse'}
print(jT.render(**params))
Adorable Armadillo