回答編集履歴
1
url以外の方法を追加
answer
CHANGED
@@ -118,6 +118,69 @@
|
|
118
118
|
{# jinja2のコメント #}
|
119
119
|
```
|
120
120
|
|
121
|
-
# col要素について。
|
121
|
+
## col要素について。
|
122
122
|
base_verb_p.htmlに空の<col>要素が並んでいますが、確認したところ、<colgroup>要素の中でしか使えない要素のようです。
|
123
|
-
不要なら削除し、必要なら<colgroup>要素の中に入れましょう。
|
123
|
+
不要なら削除し、必要なら<colgroup>要素の中に入れましょう。
|
124
|
+
|
125
|
+
# url以外の方法(2019/10/02 10:55追記)
|
126
|
+
|
127
|
+
urlに値を入れる以外で他のページに渡すとしたら、sessionを使うか、postにhidden属性で入れて渡すかのどちらかと思います。
|
128
|
+
以下、サンプルです。
|
129
|
+
|
130
|
+
```python
|
131
|
+
# app.py
|
132
|
+
from flask import Flask, session, render_template, request
|
133
|
+
|
134
|
+
app = Flask(__name__)
|
135
|
+
app.secret_key = 'secret key'
|
136
|
+
|
137
|
+
|
138
|
+
@app.route('/')
|
139
|
+
def index():
|
140
|
+
session['secret_text'] = 'secret_text session'
|
141
|
+
return render_template('index.html')
|
142
|
+
|
143
|
+
|
144
|
+
@app.route('/session_test')
|
145
|
+
def session_test():
|
146
|
+
secret_text = session['secret_text']
|
147
|
+
return secret_text
|
148
|
+
|
149
|
+
|
150
|
+
@app.route('/post_test', methods=['POST'])
|
151
|
+
def post_test():
|
152
|
+
secret_text = request.form['secret_text']
|
153
|
+
|
154
|
+
return secret_text
|
155
|
+
|
156
|
+
|
157
|
+
if __name__ == '__main__':
|
158
|
+
app.run(host='0.0.0.0', port=5000)
|
159
|
+
|
160
|
+
```
|
161
|
+
|
162
|
+
```html
|
163
|
+
<!-- templates/index.html -->
|
164
|
+
<!DOCTYPE html>
|
165
|
+
<html lang="ja">
|
166
|
+
<head>
|
167
|
+
<meta charset="UTF-8">
|
168
|
+
<title>Test Page</title>
|
169
|
+
</head>
|
170
|
+
<body>
|
171
|
+
<div>
|
172
|
+
<h2>フォームを使う</h2>
|
173
|
+
<form action="{{ url_for('post_test') }}" method="POST">
|
174
|
+
<label for="visible_text">見える入力項目</label>
|
175
|
+
<input type="text" name="visible_text" id="visible_text">
|
176
|
+
<input type="hidden" value="secret value post" name="secret_text" id="secret_text">
|
177
|
+
<input type="submit" value="入力する">
|
178
|
+
</form>
|
179
|
+
</div>
|
180
|
+
<div>
|
181
|
+
<h2>フォームは使わない</h2>
|
182
|
+
<a href="{{ url_for('session_test') }}">他のページへ</a>
|
183
|
+
</div>
|
184
|
+
</body>
|
185
|
+
</html>
|
186
|
+
```
|