[Answer]-How to create 2D list of a database table and evaluate it in a template?

1👍

it’s as easy as stated here

so, practically:

all_houses = Houses.objects.all()

will give you all the entries in your database.

from within a view, pass that variable to the template context then, in the template:

{% for house in all_houses %}
    {{ house.<column_name> }}
{% endfor %}

let me explain this bit of code: once you pass all your entries to the template, you can loop them with {% for %}

{{ house. }} means that you can extract the value you need from the column you need ( column_name ) and place it wherever you want (from whitin the for loop, obviously) so you can have (for example) {{ house.price }}, {{ house.bathrooms }} and so on, for each entry you have in your “all_entries”

Leave a comment