简体   繁体   English

使用Flask将HTML页面加载到HTML框架中

[英]Load an HTML page into an HTML frame using Flask

As of title, I'm trying to load an HTML page into an HTML frame using Flask. 从标题开始,我正在尝试使用Flask将HTML页面加载到HTML框架中。

When I open the frameset.html page on a Firefox tab (substituting {{src}} with index.html of course), the frameset behaves correctly. 当我在Firefox选项卡上打开frameset.html页面时(用{.src}}替换为index.html),框架集的行为正确。 However, whenever I run the python code, the loaded HTML page is correctly divided between the frames, but there is no trace of the index.html page in any of it. 但是,每当我运行python代码时,加载的HTML页面都会在框架之间正确划分,但是在任何页面中都没有任何index.html页面的痕迹。


main.py main.py

from flask import Flask, render_template, request

app = Flask(__name__)
page = 'index.html'

@app.route('/')
def home():
    return render_template('frameset.html', src=page)

app.run()

frameset.html frameset.html

<html>
<frameset rows="10%,80%,*">
    <frame src=''>
        <frameset cols='20%,40%,40%'>
            <frame src=''>
                <frame src='{{src}}'>
                    <frame src='' name="output">
        </frameset>
        <frame src=''>
</frameset>

</html>

index.html 的index.html

<html>

<head>
    <title>HOME</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" media="screen">
    <style type="text/css">
        .container {
            max-width: 500px;
            padding-top: 100px;
        }
    </style>
</head>

<body>
    <div class="container">
        <a href="genostats.html" target="output">GENO stats</a>

</html>

How can I solve this problem? 我怎么解决这个问题? The code I wrote here is just to test the functionality of the framesets. 我在这里编写的代码仅用于测试框架集的功能。

create another route at @app.route('index.html') rendering index.html the template, make sure the index.html file is in the templates folder @app.route('index.html')处创建另一个路由,以渲染index.html模板,并确保index.html文件位于模板文件夹中

like this: 像这样:

@app.route('/index.html')
def index():
    return render_template('index.html')

resources need to be served from either the templates folder or the static folder in flask, you can't have a resource and have it automatically served as that would be incredibly insecure, since any user then will have access to your entire server by simply changing the link. 资源需要从flask的templates folderstatic folder提供,您将无法拥有资源并自动提供资源,因为这将是非常不安全的,因为随后任何用户都可以通过简单地更改来访问整个服务器链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM