回答編集履歴
2
Javascriptのコードを追記
test
CHANGED
@@ -33,3 +33,63 @@
|
|
33
33
|
if __name__ == '__main__':
|
34
34
|
app.run()
|
35
35
|
```
|
36
|
+
|
37
|
+
**_2022/7/28追記_**
|
38
|
+
|
39
|
+
app.py
|
40
|
+
```python
|
41
|
+
from flask import Flask, render_template, send_from_directory
|
42
|
+
|
43
|
+
app = Flask(__name__)
|
44
|
+
|
45
|
+
|
46
|
+
@app.route("/")
|
47
|
+
def index():
|
48
|
+
return render_template("index.html")
|
49
|
+
|
50
|
+
@app.route("/admin")
|
51
|
+
def admin_page():
|
52
|
+
return render_template("admin.html")
|
53
|
+
|
54
|
+
@app.route("/download")
|
55
|
+
def download():
|
56
|
+
return send_from_directory("content", "file")
|
57
|
+
|
58
|
+
if __name__ == '__main__':
|
59
|
+
app.run(debug=True)
|
60
|
+
```
|
61
|
+
|
62
|
+
index.html
|
63
|
+
```html
|
64
|
+
<!DOCTYPE html>
|
65
|
+
<html>
|
66
|
+
<head>
|
67
|
+
<title>test</title>
|
68
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
69
|
+
</head>
|
70
|
+
<body>
|
71
|
+
<a href="/download" onclick="clickEvent()">download file and go to admin page</button>
|
72
|
+
</body>
|
73
|
+
</html>
|
74
|
+
|
75
|
+
<script>
|
76
|
+
function clickEvent(){
|
77
|
+
setTimeout("location.href='/admin'", 5000);
|
78
|
+
}
|
79
|
+
</script>
|
80
|
+
```
|
81
|
+
|
82
|
+
admin.html
|
83
|
+
```html
|
84
|
+
<!DOCTYPE html>
|
85
|
+
<html>
|
86
|
+
<head>
|
87
|
+
<title>test</title>
|
88
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
89
|
+
</head>
|
90
|
+
<body>
|
91
|
+
<p>admin page</p>
|
92
|
+
</body>
|
93
|
+
</html>
|
94
|
+
```
|
95
|
+
|
1
サンプルコード追記
test
CHANGED
@@ -1 +1,35 @@
|
|
1
1
|
HTMLの表示とファイルのダウンロードを分けてはだめなのですか?
|
2
|
+
|
3
|
+
フォルダ構成
|
4
|
+
![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-07-26/6cca0ff0-abff-4645-a163-f7ccba78f536.png)
|
5
|
+
|
6
|
+
```html
|
7
|
+
<!DOCTYPE html>
|
8
|
+
<html>
|
9
|
+
<head>
|
10
|
+
<title>test</title>
|
11
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
12
|
+
</head>
|
13
|
+
<body>
|
14
|
+
<a href="/download" type="button">download</a>
|
15
|
+
</body>
|
16
|
+
</html>
|
17
|
+
```
|
18
|
+
|
19
|
+
```python
|
20
|
+
from flask import Flask, render_template, send_from_directory
|
21
|
+
|
22
|
+
app = Flask(__name__)
|
23
|
+
|
24
|
+
|
25
|
+
@app.route("/")
|
26
|
+
def index():
|
27
|
+
return render_template("admin.html")
|
28
|
+
|
29
|
+
@app.route("/download")
|
30
|
+
def download():
|
31
|
+
return send_from_directory("content", "file")
|
32
|
+
|
33
|
+
if __name__ == '__main__':
|
34
|
+
app.run()
|
35
|
+
```
|