I have a web application which is made using flask and I have used pandas to_html() function to export excel as html table in the first place. I have made few changes to the html table using javascript and want to write those changes to the excel also so that they get saved everytime I reload the page.
Now, I am using Pandas read_html() function convert that html table back to excel and complete write operation
url = '127.0.0.1:5000/'
data = pd.read_html(url)
data.to_excel(filename,index=False)
But it says ValueError: Table not found
Can anybody tell whats wrong because my flask application is running when I execute this script.
This is how my index.html looks like
<div class=page>
<!-- <h1>Python</h1> -->
{% for table in tables %}
<h2>{{titles[loop.index]}}</h2>
{{ table|safe }}
{% endfor %}
</div>
and I am using this to render it
render_template('index.html',tables=[re.sub(' mytable', '" id="example', data.to_html(classes='mytable'))],
titles = ['Excel Data to Flask'])
You can parse tables to a template using:
This example is made with pandas, but I hope to help you.
Having a table like this:
ipdst proto time count
10.3.20.102 HTTP 2017-03-20 17:08:56 1
10.3.20.102 HTTP 2017-03-20 17:08:57 1
10.3.20.102 HTTP 2017-03-20 17:08:58 1
10.3.20.102 HTTP 2017-03-20 17:08:58 1
10.3.20.102 TCP 2017-03-20 17:08:59 3
app.py
import pandas as pd
from sqlalchemy import create_engine
import datetime as dt
disk_engine = create_engine('sqlite:///test.db')
df = pd.read_sql_query('SELECT * FROM data', disk_engine)
@app.route('/')
def index():
return render_template('index.html', tables=[df.to_html()], titles=['ipdst', 'proto'])
if __name__ == '__main__':
app.run(debug= True)
templates/index.html
<div class=page>
{% for table in tables %}
{{ table|safe }}
{% endfor %}
</div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.