Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #78269

Re: how to write a html to automatically display the dictionary?

Date 2014-09-24 11:27 +0200
From Jean-Michel Pichavant <jeanmichel@sequans.com>
Subject Re: how to write a html to automatically display the dictionary?
Newsgroups comp.lang.python
Message-ID <mailman.14301.1411550852.18130.python-list@python.org> (permalink)

Show all headers | View raw


----- Original Message -----
> From: "luofeiyu" <elearn2014@gmail.com>
> To: "Joel Goldstick" <joel.goldstick@gmail.com>, python-list@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.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: how to write a html to automatically display the dictionary? Jean-Michel Pichavant <jeanmichel@sequans.com> - 2014-09-24 11:27 +0200

csiph-web