So, I am new to flask web-development. I am trying to make a blog type of a page. The page has multiple panels and each panel is meant to be a blog post. The panel can contain multiple subheadings. So a single blog post is:

Panel/blog post Title
     Sub Title
      Sub TItle content
     Sub Title 2
       Sub title content 2

Now I have stored everything in a postgres database where I have a id and an info column. The ID relates to the blog post and info is a JSON dump.

Info is a JSON dictionary dump which looks like this:

{"headings": ["Attribution", "order"], "content": ["post for attribution", "post for order"]}

In the above, headings are the subtitles and content is its corresponding content.

So i am trying to get the post subtitle and its corresponding content in one iteration. I can do this in python using Zip but as far as I am aware its not available in jinja and I dont want to really use jinja for any manipulation. Any direction would be helpful? I am happy to change the format of the JSON as well if you think it would be better.

Python that works for this using Zip

for post in posts:
        for x in post:
            headings = x['headings']
            body = x['content']

            for heading, content in zip(headings, body):
                print("headings: "+str(heading))
                print("body: "+str(content)) 

0 Answers