tags:

views:

136

answers:

5

Guys,

I have dictionary and would like to produce html page where will be drawn simple html table with keys and values. How it can be done from python code?

A: 

You maybe interested by markup see http://markup.sourceforge.net/

luc
+3  A: 
output = "<html><body><table>"
for key in your_dict:
  output += "<tr><td>%s</td><td>%s</td></tr>" % (key, your_dict[key])
output += "</table></body></html>
print output
ruibm
maybe you meant 'for key, value in your_dict:' ;-)
jbochi
Remember to HTML-escape any text you concatenate into HTML, or you'll have bugs and cross-site-scripting security holes.
bobince
Fixed the value issue, thanks jbochi. Regarding HTML escaping I could have added cgi.escape(...) but I'll leave it simple.
ruibm
Thank you rui. Formatting html strings is enough for simple html table.
yart
A: 

You can use a template engine like Jinja. A list of engines for templating is available here.

jbochi
A: 

You may also consider using Mako template library.

sateesh
A: 

Along with the numerous template engines, you might consider using Python's built in Template. It will give you basic templating functionality without needing to learn (or choose) a template library.

chauncey