Search
 
SCRIPT & CODE EXAMPLE
 

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))
Comment

PREVIOUS NEXT
Code Example
Python :: how to redefine a legend in pandas 
Python :: qlineedit autocomplete python 
Python :: gonad 
Python :: in 2002 elon musk age 
Python :: update tupple in python 
Python :: convert a pandas column to int 
Python :: selenium upload file python 
Python :: find python path windows 
Python :: how to split a string from the beginning to a specific character in python 
Python :: python requests force ipv4 
Python :: how to fill an array with consecutive numbers 
Python :: python get date tomorrow 
Python :: backup django db from one database to another 
Python :: get the center of a blob opencv 
Python :: edit line if str end with pandas 
Python :: django templateview 
Python :: python beep 
Python :: how to reverse word order in python 
Python :: count missing values groupby 
Python :: pyqt text in widget frame 
Python :: how to check if user is using main file or importing the file and using in python 
Python :: df order by 
Python :: seasonal_decompose python 
Python :: remove nan particular column pandas 
Python :: how to equal two arrays in python with out linking them 
Python :: combining list of list to single list python 
Python :: how to wait in pygame 
Python :: how to manke a query in google api freebusy python 
Python :: how to send a message from google form to a python 
Python :: loading text file delimited by tab into pandas 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =