HTMLの表示とファイルのダウンロードを分けてはだめなのですか?
フォルダ構成
html
1<!DOCTYPE html>
2<html>
3 <head>
4 <title>test</title>
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6 </head>
7 <body>
8 <a href="/download" type="button">download</a>
9 </body>
10</html>
python
1from flask import Flask, render_template, send_from_directory
2
3app = Flask(__name__)
4
5
6@app.route("/")
7def index():
8 return render_template("admin.html")
9
10@app.route("/download")
11def download():
12 return send_from_directory("content", "file")
13
14if __name__ == '__main__':
15 app.run()
2022/7/28追記
app.py
python
1from flask import Flask, render_template, send_from_directory
2
3app = Flask(__name__)
4
5
6@app.route("/")
7def index():
8 return render_template("index.html")
9
10@app.route("/admin")
11def admin_page():
12 return render_template("admin.html")
13
14@app.route("/download")
15def download():
16 return send_from_directory("content", "file")
17
18if __name__ == '__main__':
19 app.run(debug=True)
index.html
html
1<!DOCTYPE html>
2<html>
3 <head>
4 <title>test</title>
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6 </head>
7 <body>
8 <a href="/download" onclick="clickEvent()">download file and go to admin page</button>
9 </body>
10</html>
11
12<script>
13 function clickEvent(){
14 setTimeout("location.href='/admin'", 5000);
15 }
16</script>
admin.html
html
1<!DOCTYPE html>
2<html>
3 <head>
4 <title>test</title>
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6 </head>
7 <body>
8 <p>admin page</p>
9 </body>
10</html>
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/07/26 01:15
2022/07/26 10:37
2022/07/27 08:40
2022/07/28 10:27