I'm trying to directly load json data to render templates using jinja2 and I'm having trouble doing so without hardcoding values. For example,
msg = template.render(posts=config[0]['context']['posts'])
Here, I've hardcoded the variable "posts" which exists in my json file and "config" is simply a python dict that I've loaded the json data into. Here's a snippet of the json file:
[
{
"url": "/",
"template": "index.html",
"context": {
"logname": "gjgk",
"posts": [
{
"postid": "3",
"owner": "ggkghj",
"likes": 1,
"comments": [
{
"owner": "dsf",
"text": "#sadf"
}
]
}
]
If "posts" was named something else, how would I reflect this in my python code? Should I change the variable names written in my template file?
Thanks