Answers for "replace the jinja template value inside the dictionary python"

1

replace the jinja template value inside the dictionary 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'"123"', template)

jT = Template(template)

params = {'text': 'some_text', 'peripherals': 'mouse'}
print(jT.render(**params))
Posted by: Guest on January-19-2022

Code answers related to "replace the jinja template value inside the dictionary python"

Python Answers by Framework

Browse Popular Code Answers by Language