Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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))
 
PREVIOUS NEXT
Tagged: #replace #jinja #template #dictionary #python
ADD COMMENT
Topic
Name
9+9 =