< 폴더 경로 >
< app.py>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
from flask import Flask, render_template, request
app = Flask(__name__)
@app.route('/')
def student():
return render_template('addrbook.html')
@app.route('/pbook',methods = ['POST', 'GET'])
def result():
if request.method == 'POST':
val = request.form #addrbook.html에서 name을 통해 submit한 값들을 val 객체로 전달
return render_template("pbook.html",result = val) #name은 key, name에 저장된 값은 value
if __name__ == '__main__':
app.run(host='0.0.0.0', port = 80, debug = True)
|
< addrbook.html >
1
2
3
4
5
6
7
8
9
10
|
<html>
<body>
<form action = "http://localhost/pbook" method = "POST">
<p>이름: <input type = "text" name = "이름" /></p>
<p>위치: <input type = "text" name = "위치" /></p>
<p>전화번호: <input type = "text" name = "전화번호" /></p>
<p><input type = "submit" value = "저장"" /></p>
</form>
</body>
</html>
|
< pbook.html >
1
2
3
4
5
6
7
8
9
10
11
12
13
|
<!doctype html>
<html>
<body>
<table border = 1>
{% for key, value in result.items() %}
<tr>
<th> {{ key }} </th>
<td> {{ value }} </td>
</tr>
{% endfor %}
</table>
</body>
</html>
|
'PRACTICE > Basic' 카테고리의 다른 글
[Flask] Cookies 예제 (0) | 2020.09.24 |
---|---|
[Flask] jinja template 활용하여 static 폴더의 자료 가져오기 (0) | 2020.09.24 |
[Flask] 컬렉션(Dictionary), Jinja template(%) 사용하여 score table 출력 (0) | 2020.09.03 |
[Flask] request 사용하여 POST, GET 출력 (0) | 2020.09.03 |
[Flask] url_for, redirect 사용하여 main, major, minor 페이지 출력 (0) | 2020.09.03 |
댓글