作者:
Neisseria (Neisseria)
2014-12-29 16:36:33其實還是 route 的問題
在 HTML 檔案裡設定的路徑,在 Flask app 裡必需要有對應的 route
否則就會跳 404 error (網頁不存在)
我跟據你的程式,試寫了一個可能的 route
但是我手頭上沒有網頁可測試,不保證 work
from flask import Flask, send_from_directory
app = Flask(__name__)
@app.route('/report')
def view_report():
return app.send_static_file('report/flexmonkey/html/index.html')
@app.route('/<path:filename>')
def send_file(filename):
return send_from_directory('report/flexmonkey/html', filename)
※ 引述《gn00618777 (非常念舊)》之銘言:
: ㄧ個 index.html ,裡面有 frameset tag,分成三區塊,這三個區塊在 index.html
: 裡分別代表其他三份 html,例子如下:
: <frameset cols="20%,80%">
: <frameset rows="30%,70%">
: <frame src="overview-frame.html" name="packageListFrame">
: <frame src="allclasses-frame.html" name="classListFrame">
: </frameset>
: <frame src="overview-summary.html" name="classFrame">
: 我在 flask 下寫一個 script test.py:
: @app.route("/")
: def hello():
: return "Hello World!"
: @app.route("/report")
: def view_report():
: url_for('static', filename='report/flexmonkey/html/')
: return send_from_directory('static', 'report/flexmonkey/html/index.html')
: 所有html都放在 report/flexmonkey/html/ 底下,server 啟動 test.py
: 客戶端無法載入其他 html
: 127.0.0.1 - - [13/Sep/2012 11:01:25] "GET /overview-frame.html HTTP/1.1" 404 -
: 127.0.0.1 - - [13/Sep/2012 11:01:25] "GET /allclasses-frame.html HTTP/1.1" 404 -
: 127.0.0.1 - - [13/Sep/2012 11:01:25] "GET /overview-summary.html HTTP/1.1" 404
: 請問這個在 test.py 要怎麼寫呢? 謝謝。