将网页加载到iFrame Flask
问题描述:
我对Flask非常新。我想在网络上创建一个移动应用程序模拟。我找到了我喜欢的bootstrap模板。我已经在Python中实现了一个小Flask应用程序来充当服务器。将网页加载到iFrame Flask
app.py
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def hello(name=None):
return render_template('index.html', name=name)
if __name__ == '__main__':
app.run()
这是index.html文件
<body>
<div class="main-row">
<h1>Fortune Estates</h1>
<div class="main_frame">
<iframe class="frame-border scroll-pane" src="templates/main.html" frameborder="0"></iframe>
</div>
</div>
<div class="copy-right">
<p>© 2016 Fortune Estates . All Rights Reserved | Design by <a href="http://w3layouts.com" target="_blank">W3layouts</a></p>
</div>
<script src="static/js/jquery.nicescroll.min.js"></script>
<script>
$(document).ready(function() {
var nice = $("html").niceScroll(); // The document page (body)
$("#div1").html($("#div1").html()+' '+nice.version);
$("#boxscroll").niceScroll(); // First scrollable DIV
});
</script>
</body>
的身体当我开始烧瓶的应用程序,我得到这个错误127.0.0.1 - - [14/Feb/2017 14:46:45] "GET /templates/main.html HTTP/1.1" 404 -
这是我的文件层次结构
.
+-- app.py
+-- templates
| +-- index.html
| +-- main.html
| ....
+-- static
| +--js
| | +--bootstrap.cs
| | ...
| +--fonts
| | ...
| +--css
| | ...
| +--images
| |
答
您引用index.html中的main.html模板,它们位于同一个目录中,请尝试在iFrame中使用src =“main.html”。
然后浏览器将发送main.html文件的另一个GET请求。您需要在服务器端通过在Flask服务器中添加新功能来覆盖它:
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def hello(name=None):
return render_template('index.html', name=name)
@app.route('/main.html')
def main():
return render_template('main.html')
if __name__ == '__main__':
app.run()
仍然不加载页面。 '127.0.0.1 - - [14/Feb/2017 15:39:53]“GET /main.html HTTP/1.1”404 -' –
尝试使用已编辑的解决方案,它应该工作得很好 –