Suppose I pass a dictionary to my jinja2 template.
In the view, I have something like
d = {} #set other template stuff into d get_params['cri'] = 'time' get_params['order'] = 'asc' d['get_params'] = get_params return d
In the template, I need to change the value of get_params keys. Logical thing
{% set get_params.cri='src' %}
with an error
TemplateSyntaxError: expected token '=', got '.'
My question is how to change the values ββpassed to the dictionary in jinja2
(This question is asked here , but I find the answer confusing, and it only answers merging)
EDIT answer:
Jinja2 provides the extension 'do'. To add this extension to the pyramid, follow these steps in the __init__.py file
#This line is alreadythere config.include('pyramid_jinja2') #Add this line config.add_jinja2_extension('jinja2.ext.do')
In the template
{% do get_params.update({'cri':'src'}) %}
python dictionary pyramid jinja2
Redbaron
source share