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


Groups > comp.lang.python > #78269 > unrolled thread

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

Started byJean-Michel Pichavant <jeanmichel@sequans.com>
First post2014-09-24 11:27 +0200
Last post2014-09-24 11:27 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

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

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

FromJean-Michel Pichavant <jeanmichel@sequans.com>
Date2014-09-24 11:27 +0200
SubjectRe: how to write a html to automatically display the dictionary?
Message-ID<mailman.14301.1411550852.18130.python-list@python.org>
----- 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.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web