Python Forum
Accessing a value of a dictionary with jinja....
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Accessing a value of a dictionary with jinja....
#1
Question 
Hi everyone,

I have a nested dictionary like this (inside my python flask file)

{"content":[{"A":"blablabala"},{"A":"blublublu"}]}
listed as DICT here after

So I need to grab "blablabala" without knowing what will be the Key (A)

inside my Jinja template I've tried

{{ DICT["content"][0] }}
but this of course return me the full nested dictionary
{"A": "blablabla"}

I've tried then in the Jinja template
{%- set extraction = list(DICT["content"][0].values())  %}
{{ extraction[0] }}
But this give me the following error
jinja2.exception.UndefinedError: 'list' is undefined
Dodgy any ideas ?
[Image: NfRQr9R.jpg]
Reply


Messages In This Thread
Accessing a value of a dictionary with jinja.... - by SpongeB0B - Aug-06-2021, 06:44 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Solved] Browser won't parse text from yaml loaded into Jinja SpongeB0B 1 952 Jul-07-2022, 09:37 PM
Last Post: SpongeB0B
  Jinja sort values from request.form SpongeB0B 2 2,188 Jul-26-2020, 07:41 AM
Last Post: SpongeB0B
  how to create dynamic arguments to be passed in jinja template in url_for function? experimental 1 2,741 May-01-2020, 05:50 PM
Last Post: Larz60+
  Flask tutorial errors in jinja, auth undefined Ecniv 2 2,454 May-03-2019, 02:04 PM
Last Post: Ecniv
  flask sqlite jinja accessing and updating database help pascale 5 4,086 Feb-11-2019, 03:49 PM
Last Post: pascale
  display multiple sensors on webpage python flask jinja pascale 6 5,198 Jan-29-2019, 10:10 AM
Last Post: pascale

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020