List of dictionaries - How to render in mako

Skip to first unread message

Javi D R

Jun 16, 2020, 11:39:46 AM6/16/20
to Mako Templates for Python

I am starting to work with Mako and im finding some problems. Apologies if the question is dumb

I am finding two problems. The first one, is that i can't send a list of data to mako to render it in an HTML. 

I have a list of dictionaries like this:

[{'name' : 'javi', 'country' : 'Spain'}, {'name' : 'john', 'country' : 'UK'}]

And i want to create an HTML like this:

javi - Spain
john - UK

What is the best way of doing this with Mako? As far as i know, you can't send a list as a parameter to render method in Mako, isnt it?

The second one comes after i tried to created the list as a parameter in the dictionary, something like this:

{'data' :[{'name' : 'javi', 'country' : 'Spain'}, {'name' : 'john', 'country' : 'UK'}]}

My template is as follows:

%for monster in monsters:

But then, I have this error:

AttributeError: 'dict' object has no attribute 'name'

What is the right way to access a key inside a dictionary?


Kostiantyn Ivashchenko

Jun 16, 2020, 3:30:05 PM6/16/20
in first case try this way:
% for d in list_dict:
<p>${d['name']} - ${d['country']}</p>
% endfor

in second:
% for d in compl_list_dict:
<p>${d['data'][0]['name']} - ${d['data'][1]['country']}</p>
% endfor

вт, 16 черв. 2020, 18:39 користувач Javi D R <> пише:
You received this message because you are subscribed to the Google Groups "Mako Templates for Python" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
Reply all
Reply to author
0 new messages