Relative Content

Tag Archive for flaskjinja2flask-sqlalchemy

Flask loop through a db query in jinja2 with filter

I have a category table and a post table. For each category there are many posts. There is a foreign key relationship between these two tables so that each row in the post table also has a column for associate category id. Now, I’m querying category table and sending it to the jinja2 template. In the template, I am looping through each category and displaying all posts associated with it. Here is the code: