问候
我有一个 flask 应用程序:
@app.route('/test')
def test():
return render_template('index.html')
在index.html中我有:
<!DOCTYPE html>
<meta charset="utf-8">
<style type="text/css">
.node {
cursor: pointer;
}
.overlay{
background-color: #e6d1ee;
}
.node circle {
fill: #fff;
stroke: #4d4bb4;
stroke-width: 2px;
}
.node text {
font-size:10px;
font-family:sans-serif;
}
.link {
fill: none;
stroke: #7acc7e;
stroke-width: 2px;
}
.templink {
fill: none;
stroke: #ff8285;
stroke-width: 3px;
}
.ghostCircle.show{
display:block;
}
.ghostCircle, .activeDrag .ghostCircle{
display: none;
}
</style>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="MyTree.js"></script>
<body>
<div id="tree-container"></div>
</body>
当我在浏览器中运行此 html 代码时,它显示了一个很好的 graph
但是后来我使用带有 render_template 的 Flask 来渲染它,它绝对显示了
如何修复它?
抱歉这个巨大的代码块,我不确定这是 html 问题
更新:
实际上是的,问题出在静态的东西上。现在我的浏览器可以获取js文件了。但另一个问题又出现了。在 MyTree.js 中我使用
treeJSON = d3.json("{{ url_for('static', filename='dota.json') }}", function(error, treeData)
并且 dota.json 未在浏览器中加载。但它与 MyTree.js 位于同一目录中,位于静态目录中。
最佳答案
我想说的是,目前浏览器尚未获取您的 MyTree.js 文件(您可以在开发人员控制台中检查这一点)。您需要将 MyTree.js 文件放置在静态目录中,并在 HTML 中引用静态端点:
<script src="{{ url_for('static', filename='MyTree.js') }}"></script>
关于python - Flask render_template 不渲染任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43632838/