python - Table creating gets messed up -


i trying create table using below html code in python,it works instances cases table gets messed below,please see screen shot..any inputs on wrong?how debug it?any workarounds fix it?really appreciate inputs

html source messed row: http://pastie.org/8263837

  ...........   ...........   gerritmailbody = gerritmailbody + "<td>" + gerritinfo['targetname'].rstrip('\n') + "</td>"   gerritmailbody = gerritmailbody + "<td>" + gerritinfo['assignee'].rstrip('\n') + "</td>"   usernames.append(gerritinfo['assignee'].rstrip('\n'))    #below block getting messed   gerritmailbody = gerritmailbody + "<td height=\"150\%\">"   gerritmailbody = gerritmailbody + "<table>"     item in gerritinfo['gerriturl']:     gerritmailbody = gerritmailbody + "<tr>"     gerritmailbody = gerritmailbody + "<td>"     gerritmailbody = gerritmailbody + item.rstrip('\n/') + "<br>"     gerritmailbody = gerritmailbody + "</td>"     gerritmailbody = gerritmailbody + "</tr>"    gerritmailbody = gerritmailbody + "</table>"   gerritmailbody = gerritmailbody + "</td>"    ............   ............ 

constructing html way in python not readable @ , difficult maintain. switch template engine mako:

from mako.template import template print template("hello ${data}!").render(data="world") 

define html file message body template, fill data via render , message string:

from mako.template import template  mytemplate = template(filename='body.html') print mytemplate.render(data=data) 

trust me, make life easier , sleep more peaceful.


possible reason of messed html data inserting html contains characters (<, <, &) should escaped. consider calling cgi.escape() on every item inserting. see: what's easiest way escape html in python?

again, escaping works out-of-the-box in of template engines out there.

hope helps.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -