使用Flask将HTML页面加载到HTML框架中 [英] Load an HTML page into an HTML frame using Flask

查看:108
本文介绍了使用Flask将HTML页面加载到HTML框架中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从标题开始,我正在尝试使用Flask将HTML页面加载到HTML框架中.

As of title, I'm trying to load an HTML page into an HTML frame using Flask.

当我在Firefox选项卡上打开frameset.html页面时(用{.src}}替换为index.html),框架集的行为正确.但是,每当我运行python代码时,加载的HTML页面都会在帧之间正确划分,但是在任何页面中都没有找到index.html页面的踪迹.

When I open the frameset.html page on a Firefox tab (substituting {{src}} with index.html of course), the frameset behaves correctly. 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.


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

<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

<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.

推荐答案

@ app.route('index.html')处创建另一条路线,渲染 index.html 模板,请确保 index.html 文件位于模板文件夹中

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')
def index():
    return render_template('index.html')

资源需要从flask的 templates文件夹 static文件夹提供,您没有资源,可以自动将其提供令人难以置信的是不安全,因为任何用户都可以通过简单地更改链接来访问整个服务器.

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将HTML页面加载到HTML框架中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆