質問編集履歴
5
secret_keyの簡略化
test
CHANGED
File without changes
|
test
CHANGED
@@ -66,7 +66,7 @@
|
|
66
66
|
|
67
67
|
app = Flask(__name__)
|
68
68
|
|
69
|
-
app.config['SECRET_KEY'] = '34567890
|
69
|
+
app.config['SECRET_KEY'] = '1234567890'
|
70
70
|
|
71
71
|
|
72
72
|
|
@@ -158,7 +158,7 @@
|
|
158
158
|
|
159
159
|
<!-- Bootstrap CSS -->
|
160
160
|
|
161
|
-
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
|
161
|
+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" crossorigin="anonymous">
|
162
162
|
|
163
163
|
|
164
164
|
|
@@ -340,7 +340,7 @@
|
|
340
340
|
|
341
341
|
<!-- Bootstrap CSS -->
|
342
342
|
|
343
|
-
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
|
343
|
+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" crossorigin="anonymous">
|
344
344
|
|
345
345
|
|
346
346
|
|
4
テストコードの添付
test
CHANGED
File without changes
|
test
CHANGED
@@ -32,12 +32,52 @@
|
|
32
32
|
|
33
33
|
|
34
34
|
|
35
|
-
###
|
35
|
+
### テストコード
|
36
|
+
|
37
|
+
|
38
|
+
|
36
|
-
|
39
|
+
ファイル構造
|
40
|
+
|
37
|
-
|
41
|
+
.
|
42
|
+
|
43
|
+
├── app.py
|
44
|
+
|
45
|
+
└── templates
|
46
|
+
|
47
|
+
---├── evaluate.html
|
48
|
+
|
49
|
+
---└── evaluated.html
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
**app.py**
|
38
54
|
|
39
55
|
```python
|
40
56
|
|
57
|
+
from flask import Flask, render_template, url_for, redirect
|
58
|
+
|
59
|
+
from wtforms.validators import DataRequired
|
60
|
+
|
61
|
+
from flask_wtf import FlaskForm
|
62
|
+
|
63
|
+
from wtforms import StringField, PasswordField, SubmitField, BooleanField, SelectField, TextAreaField, IntegerField
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
app = Flask(__name__)
|
68
|
+
|
69
|
+
app.config['SECRET_KEY'] = '345678907654324560909345'
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
class Submit(FlaskForm):
|
76
|
+
|
77
|
+
year = IntegerField('評価年', validators=[DataRequired()], default = 2020)
|
78
|
+
|
79
|
+
submit = SubmitField('登録')
|
80
|
+
|
41
81
|
|
42
82
|
|
43
83
|
class Evaluation(FlaskForm):
|
@@ -48,108 +88,318 @@
|
|
48
88
|
|
49
89
|
|
50
90
|
|
51
|
-
|
91
|
+
@app.route('/', methods=['GET','POST'])
|
92
|
+
|
52
|
-
|
93
|
+
def home():
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
form = Submit()
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
list_of_form = []
|
102
|
+
|
103
|
+
list_of_function_name = ['Column1', 'Column2', 'Column3']
|
104
|
+
|
105
|
+
|
106
|
+
|
53
|
-
for a in range(len(list_of_function_name)):
|
107
|
+
for a in range(len(list_of_function_name)):
|
54
|
-
|
108
|
+
|
55
|
-
list_of_form.append(
|
109
|
+
list_of_form.append(Evaluation())
|
56
|
-
|
57
|
-
|
58
|
-
|
110
|
+
|
59
|
-
|
111
|
+
print(list_of_form)
|
60
|
-
|
112
|
+
|
113
|
+
|
114
|
+
|
61
|
-
list_of_form_dictionary = dict(zip(list_of_function_name, list_of_form))
|
115
|
+
list_of_form_dictionary = dict(zip(list_of_function_name, list_of_form))
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
if form.validate_on_submit():
|
120
|
+
|
121
|
+
for a in range(len(list_of_form)):
|
122
|
+
|
123
|
+
print(print(list_of_form[a].value.data))
|
124
|
+
|
125
|
+
print(print(list_of_form[a].message.data))
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
return render_template('evaluated.html', title = '評価値', list_of_form = list_of_form )
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
return render_template('evaluate.html', title = 'テスト', form = form, evaluation_list = list_of_form_dictionary)
|
134
|
+
|
135
|
+
|
62
136
|
|
63
137
|
```
|
64
138
|
|
65
139
|
|
66
140
|
|
141
|
+
**evaluate.html**
|
142
|
+
|
67
143
|
```HTML
|
68
144
|
|
69
|
-
|
70
|
-
|
71
|
-
|
145
|
+
<!DOCTYPE html>
|
146
|
+
|
147
|
+
<html>
|
148
|
+
|
149
|
+
<head>
|
150
|
+
|
151
|
+
<!-- Required meta tags -->
|
152
|
+
|
153
|
+
<meta charset="utf-8">
|
154
|
+
|
155
|
+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
<!-- Bootstrap CSS -->
|
160
|
+
|
161
|
+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
{% if title %}
|
166
|
+
|
167
|
+
<title>{{ title }}</title>
|
168
|
+
|
169
|
+
{% else %}
|
170
|
+
|
171
|
+
<title>HOME</title>
|
172
|
+
|
173
|
+
{% endif %}
|
174
|
+
|
175
|
+
</head>
|
176
|
+
|
177
|
+
<body>
|
178
|
+
|
179
|
+
<header class="site-header">
|
180
|
+
|
181
|
+
</header>
|
182
|
+
|
183
|
+
<main role="main" class="container">
|
184
|
+
|
185
|
+
<div class="row">
|
186
|
+
|
187
|
+
<div class="col-md-12">
|
188
|
+
|
189
|
+
<div class="container">
|
190
|
+
|
191
|
+
<form method="POST" action="">
|
192
|
+
|
193
|
+
{{ form.hidden_tag() }}
|
194
|
+
|
195
|
+
<fieldset class="form-group">
|
196
|
+
|
197
|
+
<legend class="border-bottom mb-4">評価</legend>
|
198
|
+
|
199
|
+
<div class="form-group">
|
200
|
+
|
201
|
+
{{ form.year.label(class="form-control-label") }}
|
202
|
+
|
203
|
+
{% if form.year.errors %}
|
204
|
+
|
205
|
+
{{ form.year(class="form-control form-control-lg is-invalid") }}
|
206
|
+
|
207
|
+
<div class="invalid-feedback">
|
208
|
+
|
209
|
+
{% for error in form.year.errors %}
|
210
|
+
|
211
|
+
<span>エラー</span>
|
212
|
+
|
213
|
+
{% endfor %}
|
214
|
+
|
215
|
+
</div>
|
216
|
+
|
217
|
+
{% else %}
|
218
|
+
|
219
|
+
{{ form.year(class="form-control form-control-lg") }}
|
220
|
+
|
221
|
+
{% endif %}
|
222
|
+
|
223
|
+
</div>
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
{% for name, evaluation_form in evaluation_list.items() %}
|
228
|
+
|
229
|
+
<h3>{{ name[5:] }}</h3>
|
230
|
+
|
231
|
+
<div class="form-group">
|
232
|
+
|
233
|
+
{{ evaluation_form }}
|
234
|
+
|
235
|
+
{{ evaluation_form.value.label(class="form-control-label") }}
|
236
|
+
|
237
|
+
{% if evaluation_form.value.errors %}
|
238
|
+
|
239
|
+
{{ evaluation_form.value(class="form-control form-control-lg is-invalid") }}
|
240
|
+
|
241
|
+
<div class="invalid-feedback">
|
242
|
+
|
243
|
+
{% for error in evaluation_form.value.errors %}
|
244
|
+
|
245
|
+
<span>エラー</span>
|
246
|
+
|
247
|
+
{% endfor %}
|
248
|
+
|
249
|
+
</div>
|
250
|
+
|
251
|
+
{% else %}
|
252
|
+
|
253
|
+
{{ evaluation_form.value(class="form-control form-control-lg") }}
|
254
|
+
|
255
|
+
{% endif %}
|
256
|
+
|
257
|
+
</div>
|
258
|
+
|
259
|
+
<div class="form-group">
|
260
|
+
|
261
|
+
{{ evaluation_form.message.label(class="form-control-label") }}
|
262
|
+
|
263
|
+
{% if evaluation_form.message.errors %}
|
264
|
+
|
265
|
+
{{ evaluation_form.message(class="form-control form-control-lg is-invalid") }}
|
266
|
+
|
267
|
+
<div class="invalid-feedback">
|
268
|
+
|
269
|
+
{% for error in evaluation_form.message.errors %}
|
270
|
+
|
271
|
+
<span>エラー</span>
|
272
|
+
|
273
|
+
{% endfor %}
|
274
|
+
|
275
|
+
</div>
|
276
|
+
|
277
|
+
{% else %}
|
278
|
+
|
279
|
+
{{ evaluation_form.message(class="form-control form-control-lg") }}
|
280
|
+
|
281
|
+
{% endif %}
|
282
|
+
|
283
|
+
</div>
|
284
|
+
|
285
|
+
{% endfor %}
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
</fieldset>
|
292
|
+
|
293
|
+
|
72
294
|
|
73
295
|
<div class="form-group">
|
74
296
|
|
75
|
-
{{ evaluation_form }}
|
76
|
-
|
77
|
-
{{ evaluation_form.value.label(class="form-control-label") }}
|
78
|
-
|
79
|
-
{% if evaluation_form.value.errors %}
|
80
|
-
|
81
|
-
{{ evaluation_form.value(class="form-control form-control-lg is-invalid") }}
|
82
|
-
|
83
|
-
<div class="invalid-feedback">
|
84
|
-
|
85
|
-
{% for error in evaluation_form.value.errors %}
|
86
|
-
|
87
|
-
<span>エラー</span>
|
88
|
-
|
89
|
-
{% endfor %}
|
90
|
-
|
91
|
-
</div>
|
92
|
-
|
93
|
-
{% else %}
|
94
|
-
|
95
|
-
|
297
|
+
{{ form.submit(class="btn btn-outline-info") }}
|
96
|
-
|
97
|
-
{% endif %}
|
98
298
|
|
99
299
|
</div>
|
100
300
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
301
|
+
</form>
|
302
|
+
|
303
|
+
</div>
|
304
|
+
|
305
|
+
</div>
|
306
|
+
|
307
|
+
</div>
|
308
|
+
|
309
|
+
</main>
|
310
|
+
|
311
|
+
</body>
|
312
|
+
|
313
|
+
</html>
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
```
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
**evaluated.html**
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
```HTML
|
326
|
+
|
327
|
+
<!DOCTYPE html>
|
328
|
+
|
329
|
+
<html>
|
330
|
+
|
331
|
+
<head>
|
332
|
+
|
333
|
+
<!-- Required meta tags -->
|
334
|
+
|
335
|
+
<meta charset="utf-8">
|
336
|
+
|
337
|
+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
<!-- Bootstrap CSS -->
|
342
|
+
|
343
|
+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
{% if title %}
|
348
|
+
|
349
|
+
<title>{{ title }}</title>
|
350
|
+
|
351
|
+
{% else %}
|
352
|
+
|
353
|
+
<title>HOME</title>
|
354
|
+
|
355
|
+
{% endif %}
|
356
|
+
|
357
|
+
</head>
|
358
|
+
|
359
|
+
<body>
|
360
|
+
|
361
|
+
<header class="site-header">
|
362
|
+
|
363
|
+
</header>
|
364
|
+
|
365
|
+
<main role="main" class="container">
|
366
|
+
|
367
|
+
<div class="row">
|
368
|
+
|
369
|
+
<div class="col-md-12">
|
370
|
+
|
371
|
+
<div class="container">
|
372
|
+
|
373
|
+
{{ list_of_form }}
|
374
|
+
|
375
|
+
{% for written in list_of_form %}
|
376
|
+
|
377
|
+
<h3>{{ written.value.data }}</h3>
|
378
|
+
|
379
|
+
<h4>{{ written.message.data }}</h4>
|
380
|
+
|
381
|
+
<br>
|
126
382
|
|
127
383
|
{% endfor %}
|
128
384
|
|
385
|
+
</div>
|
386
|
+
|
387
|
+
</div>
|
388
|
+
|
389
|
+
</div>
|
390
|
+
|
391
|
+
</main>
|
392
|
+
|
393
|
+
</body>
|
394
|
+
|
395
|
+
</html>
|
396
|
+
|
397
|
+
|
398
|
+
|
129
399
|
```
|
130
400
|
|
131
401
|
|
132
402
|
|
133
|
-
```python
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
# 例えばlen(list_of_function_name)が3であった時の出力テスト
|
138
|
-
|
139
|
-
print(list_of_form[0].value.data)
|
140
|
-
|
141
|
-
print(list_of_form[1].value.data)
|
142
|
-
|
143
|
-
print(list_of_form[2].value.data)
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
# なお、異なる値を入力していっても、全てlist_of_form[0].value.dataで出力されるものと同じものが以降のprint文でも出力されてしまう。
|
148
|
-
|
149
|
-
```
|
150
|
-
|
151
|
-
|
152
|
-
|
153
403
|
### 試したこと
|
154
404
|
|
155
405
|
|
@@ -176,4 +426,6 @@
|
|
176
426
|
|
177
427
|
Flask-WTF==0.14.2
|
178
428
|
|
429
|
+
WTForms==2.2.1
|
430
|
+
|
179
431
|
Python 3.7.4
|
3
表記の訂正
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,17 +20,15 @@
|
|
20
20
|
|
21
21
|
|
22
22
|
|
23
|
-
================================================
|
24
|
-
|
25
23
|
1. FlaskFormの定義
|
26
24
|
|
27
25
|
2. render_template時にFormを渡す
|
28
26
|
|
29
27
|
3. validate関数にエラーがない場合はデータベースにあげる
|
30
28
|
|
31
|
-
================================================
|
32
29
|
|
30
|
+
|
33
|
-
3.
|
31
|
+
"3."のデータベースにデータをあげることはできますが、データが入力されたものと一致していない。
|
34
32
|
|
35
33
|
|
36
34
|
|
2
プログラムの流れの記述と疑問箇所の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -17,6 +17,20 @@
|
|
17
17
|
|
18
18
|
|
19
19
|
submitフォームは別のFlaskFormにて定義しています。
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
================================================
|
24
|
+
|
25
|
+
1. FlaskFormの定義
|
26
|
+
|
27
|
+
2. render_template時にFormを渡す
|
28
|
+
|
29
|
+
3. validate関数にエラーがない場合はデータベースにあげる
|
30
|
+
|
31
|
+
================================================
|
32
|
+
|
33
|
+
3. のデータベースにデータをあげることはできますが、データが入力されたものと一致していない。
|
20
34
|
|
21
35
|
|
22
36
|
|
1
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
### 前提・実現したいこと
|
2
2
|
|
3
3
|
|
4
|
-
|
5
|
-
ここに質問の内容を詳しく書いてください。
|
6
4
|
|
7
5
|
Flaskを用いて評価フォームを準備し、入力されたデータをデータベースにあげるという一連の関数を作成中です。
|
8
6
|
|