yart
yart

Reputation: 7805

Get html output from python code

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?

Upvotes: 5

Views: 14603

Answers (5)

chauncey
chauncey

Reputation: 676

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.

Upvotes: 0

rui
rui

Reputation: 11284

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

Upvotes: 10

sateesh
sateesh

Reputation: 28663

You may also consider using Mako template library.

Upvotes: 1

jbochi
jbochi

Reputation: 29634

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

Upvotes: 2

luc
luc

Reputation: 43096

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

Upvotes: 1

Related Questions