Python Jinja2 Give variable value to render funtion

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Python Jinja2 Give variable value to render funtion



I have my python code, I want to give a dico in my render() funtion to remplace value for the template, but when I use a dico in python it does no work


THIS_DIR = os.path.dirname(os.path.abspath(__file__))
j2_env = Environment(loader=FileSystemLoader(THIS_DIR),
trim_blocks=True)



the funtion render() expected something like that :


j2_env.get_template('file.yml').render(value1='apple',value2='0.1')



I try this, but he doesn't remplace value :


resul = "value1='apple',value2='0.1'"
j2_env.get_template('file.yml').render(resul)



I got this error :


File "/usr/local/lib/python3.6/site-packages/jinja2/asyncsupport.py", line 76, in render
return original_render(self, *args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/jinja2/environment.py", line 1003, in render
vars = dict(*args, **kwargs)
ValueError: dictionary update sequence element #0 has length 1; 2 is required



Indeed, If a have a multiple value to give in render(), I can't give directly the string to render function.



So I try this with dictionary :


my_dict = {'value1': 'apple', 'value2': '4'}
j2_env.get_template('file.yml').render(my_dict=my_dict)



But the values doesn't change.



Thanks for you help









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Keycloak server returning user_not_found error when user is already imported with LDAP

PHP parse/syntax errors; and how to solve them?

How to scale/resize CVPixelBufferRef in objective C, iOS