how to write a html to automatically display the dictionary?

Jean-Michel Pichavant jeanmichel at sequans.com
Wed Sep 24 11:27:24 CEST 2014


----- Original Message -----
> From: "luofeiyu" <elearn2014 at gmail.com>
> To: "Joel Goldstick" <joel.goldstick at gmail.com>, python-list at python.org
> Sent: Wednesday, 24 September, 2014 1:06:25 AM
> Subject: Re: how to write a html to automatically display the dictionary?
> 
> 
> how can i create the proper html file with Jinjia 2 or other temple?
> 

template :)

I'm surprised you didn't figure it out by looking at jinja2 examples in their documentation.

python 2.7 :

from jinja2 import Template
template = Template('''
<table border=1>
<tr>{% for k in x.keys()%}<th>{{k}}</th>{%endfor%}</tr>
<tr>{% for k in x.values()%}<td>{{k}}</td>{%endfor%}</tr>
</table>''')

with open('foo.html', 'w') as myFile:
    myFile.write(template.render(x={'f1':1,'f2':2,'f3':3}))

Regards,

JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.


More information about the Python-list mailing list