简体   繁体   中英

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.

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.


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()

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

<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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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