Access Values From A Dict In A Function Called In A Jinja Expression
I'm passing a dict from a Flask view to a Jinja template. I can render the values in the dict, but if I try to pass them to url_for I get UndefinedError: 'dict object' has no attr
Solution 1:
Instead of "{{ url_for('delete_entry', btnId= entry.eId) }}"
you should have "{{ url_for('delete_entry', btnId= entry['eId']) }}"
because elements in a dictionary should be accessed by their get
method. The only reason that {{ entry.title }}
works is because of jinja2.
Essenially {{ entry.title }}
gets evaluated by jinja whereas "{{ url_for('delete_entry', btnId= entry.eId) }}"
gets evaluated by python and breaks.
Post a Comment for "Access Values From A Dict In A Function Called In A Jinja Expression"