python flask 中加载的HTML 页面 的js中 需要加载CSV 文件 但找不到路径
pythonflask中加载的HTML页面的js中需要加载CSV文件但找不到路径我把csv文件放在html文件的同目录下,正常用浏览器打开html可以加载csv文件,但是...
python flask 中加载的HTML 页面 的js中 需要加载CSV 文件 但找不到路径
我把 csv 文件放在 html 文件的同目录下,正常用浏览器打开 html 可以加载csv文件,但是放在flask中就找不到了
python :
from flask import Flask,render_template
app = Flask(__name__)
@app.route('/')
def root():
#return app.send_static_file('index.html')
return render_template("index.html")
if __name__ == "__main__":
app.run(host="0.0.0.0",port=8088, debug=True)
html:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<html>
<head>
<script type="text/javascript" src="http://dygraphs.com/1.0.1/dygraph-combined.js"></script><!—用这一个js就OK,封装了这个框架所有基本的JS,不包括后面的excanvas.js interaction.js-->
</head>
<body>
<div id="graphdiv2" style="float:left; width:93%; height:300px;"></div>
<div style="float:rigth; padding-top:30px" >
<form name="myForm">
<input style="float:right" type="button" name="mybutton1" value="停止刷新" onFocus=whether_refresh1() id="test1">
</form>
<form name="myForm">
<input style="float:right" type="button" name="mybutton2" value="开始刷新" onFocus=whether_refresh2() id="test2">
</form>
</div>
<script type="text/javascript">
function refresh(){
g2 = new Dygraph(
document.getElementById("graphdiv2"),//图表显示的位置
"temperatures.csv", // 数据的所在位置
{
title:"电信流量监控",
xlabel:"时间轴",
//legend: 'always',
labelsDivStyles: { 'textAlign': 'right' },
showRangeSelector: true,
ylabel:"流量轴(Gb)",
drawPoints: true,
stackedGraph: true
} // options 可选配置参数
);
}
refresh()
document.all.mybutton2.style.display="none";
var t2
t2 = window.setInterval("refresh()",5000);
function whether_refresh1(){
document.all.mybutton2.style.display="block";
document.all.mybutton1.style.display="none";
window.clearInterval(t2);
}
function whether_refresh2(){
document.all.mybutton1.style.display="block";
document.all.mybutton2.style.display="none";
t2 = window.setInterval("refresh()",5000);
}
</script>
</body>
</html> 展开
我把 csv 文件放在 html 文件的同目录下,正常用浏览器打开 html 可以加载csv文件,但是放在flask中就找不到了
python :
from flask import Flask,render_template
app = Flask(__name__)
@app.route('/')
def root():
#return app.send_static_file('index.html')
return render_template("index.html")
if __name__ == "__main__":
app.run(host="0.0.0.0",port=8088, debug=True)
html:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<html>
<head>
<script type="text/javascript" src="http://dygraphs.com/1.0.1/dygraph-combined.js"></script><!—用这一个js就OK,封装了这个框架所有基本的JS,不包括后面的excanvas.js interaction.js-->
</head>
<body>
<div id="graphdiv2" style="float:left; width:93%; height:300px;"></div>
<div style="float:rigth; padding-top:30px" >
<form name="myForm">
<input style="float:right" type="button" name="mybutton1" value="停止刷新" onFocus=whether_refresh1() id="test1">
</form>
<form name="myForm">
<input style="float:right" type="button" name="mybutton2" value="开始刷新" onFocus=whether_refresh2() id="test2">
</form>
</div>
<script type="text/javascript">
function refresh(){
g2 = new Dygraph(
document.getElementById("graphdiv2"),//图表显示的位置
"temperatures.csv", // 数据的所在位置
{
title:"电信流量监控",
xlabel:"时间轴",
//legend: 'always',
labelsDivStyles: { 'textAlign': 'right' },
showRangeSelector: true,
ylabel:"流量轴(Gb)",
drawPoints: true,
stackedGraph: true
} // options 可选配置参数
);
}
refresh()
document.all.mybutton2.style.display="none";
var t2
t2 = window.setInterval("refresh()",5000);
function whether_refresh1(){
document.all.mybutton2.style.display="block";
document.all.mybutton1.style.display="none";
window.clearInterval(t2);
}
function whether_refresh2(){
document.all.mybutton1.style.display="block";
document.all.mybutton2.style.display="none";
t2 = window.setInterval("refresh()",5000);
}
</script>
</body>
</html> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询