Python 无法使用FLASK查看HTML页面-出现404错误

Python 无法使用FLASK查看HTML页面-出现404错误,python,html,json,flask,vis.js,Python,Html,Json,Flask,Vis.js,我可以使用flask浏览到我的主页index.html页面,但当我单击index页面上的按钮时,该页面被定向到mytopo.html页面,但没有出现拓扑视图,并且出现错误。尝试转到mytopo.html页面时,我在下面遇到错误。似乎找不到我的json文件(mytopo.json) 这是烧瓶项目的结构 mywebfolder myapp.py --- main file and run server static --- for images image1.jpg templat

我可以使用flask浏览到我的主页index.html页面,但当我单击index页面上的按钮时,该页面被定向到mytopo.html页面,但没有出现拓扑视图,并且出现错误。尝试转到mytopo.html页面时,我在下面遇到错误。似乎找不到我的json文件(mytopo.json)

这是烧瓶项目的结构

mywebfolder
  myapp.py --- main file and run server
  static --- for images
   image1.jpg
  templates --- all html files are here
   index.html
   mytopo.html
  data --- my json file is store here
   mytopo.json

myapp.py

app = Flask(__name__)

#Function for index page
@app.route('/')
def startPage():
    bodyText=Markup("<b>MAIN PAGE</b>")
    return render_template('index.html', bodyText=bodyText)

#topology view
@app.route('/mytopo')
def mytopo():
    return render_template("mytopo.html")
app=Flask(\uuuuu name\uuuuuu)
#用于索引页的函数
@应用程序路径(“/”)
def起始页():
bodyText=标记(“主页”)
返回呈现模板('index.html',bodyText=bodyText)
#拓扑视图
@应用程序路径(“/mytopo”)
def mytopo():
返回渲染模板(“mytopo.html”)
index.html

<button style="width:10px;height:10px"><font size="6"><a href="mytopo">Topology View</a></font></button>

mytopo.html使用vis.js和json文件(mytopo.json)查看拓扑

var json=$.getJSON(“mytopo.json”)
.完成(功能(数据){
风险值数据={
节点:data.nodes,
边:data.edges
};
var网络=新的可视网络(容器、数据、选项);
});
var container=document.getElementById('mynetwork');

我真的很感激有人能给我带路……请帮助我,谢谢你。

简而言之,你没有提供JSON文件的途径。在您的情况下,必须创建一个新的视图函数,以使用URL规则
/mytopo.JSON

从flask导入从\u目录发送\u
@app.route(“/mytopo.json”)
def mytopo_json():
从目录返回发送路径(app.root路径'data/mytopo.json')

(代码还没有测试,如果不起作用,请告诉我)

Hi…我将测试它并更新结果…谢谢
<button style="width:10px;height:10px"><font size="6"><a href="mytopo">Topology View</a></font></button>
var json = $.getJSON("mytopo.json")
  .done(function(data){
    var data = {
      nodes: data.nodes,
      edges: data.edges
    };
    var network = new vis.Network(container, data, options);
  });

var container = document.getElementById('mynetwork');

</script>