Python Forum
Pandas tuple list returning html string
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pandas tuple list returning html string
#1
Hi

I am learning python flask and trying to generate html from python list of tuples using pandas dataframe and to_html method
(refer https://pandas.pydata.org/pandas-docs/ve..._html.html)

here is my python code
output = [('inst1','insttype1','instregion1','instname1',insttime1'),('inst2','insttype2','instregion2','instname2',insttime2')]
df = pd.DataFrame(output, columns=['Instance-Id', 'Instance-Type', 'Region', 'Instance-Name', 'Instane-Launch-Time'])

htmls = df.to_html(classes="reports")
return htmls
here is my python flask and template code

@app.route("reports", methods = ['POST'])
def reports():
    result = t1.getEC2(profilename=request.form['awsprofile'])
    return render_template('output.html', output=result)
<!DOCTYPE html>
<html>
<head>
<title>Reports</title>
</head>
<body>
<h1>Reports Testing</h1><br>
{{ output }}
</body>
</html>


When I execute this, the "output" result gets printed as a continous string instead of a table..whereas if I paste directly via https://html5-editor.net/ ..I see the table printed

can anyone guide me here what I am doing wrong ?

Thanks
Shan
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Populating list items to html code and create individualized html code files ChainyDaisy 0 1,561 Sep-21-2022, 07:18 PM
Last Post: ChainyDaisy
  HTML multi select HTML listbox with Flask/Python rfeyer 0 4,532 Mar-14-2021, 12:23 PM
Last Post: rfeyer
  Scrape for html based on url string and output into csv dana 13 5,326 Jan-13-2021, 03:52 PM
Last Post: snippsat
  Python3 + BeautifulSoup4 + lxml (HTML -> CSV) - How to loop to next HTML/new CSV Row BrandonKastning 0 2,329 Mar-22-2020, 06:10 AM
Last Post: BrandonKastning
  Decoding html to text string PeterPython 1 2,632 Aug-12-2018, 07:23 PM
Last Post: Larz60+
  How to use BeautifulSoup4 with pandas series type of html data? PrateekG 4 4,854 Apr-26-2018, 07:33 AM
Last Post: PrateekG
  Pandas reading html returning NaT iFunKtion 1 4,541 Nov-09-2016, 05:31 PM
Last Post: snippsat
  HTML select options from python list adi.6194 4 11,558 Oct-20-2016, 01:31 PM
Last Post: adi.6194

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020