html page
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
function hey_get() {
$.ajax({
type: "GET",
url: "/test?title_give=봄날은간다",
data: {},
success: function (response) {
console.log(response)
}
})
}
function hey_post() {
$.ajax({
type: "POST",
url: "/test",
data: {title_give: '봄날은간다'},
success: function (response) {
console.log(response['msg'])
}
})
}
</script>
</head>
<body>
<h1>나의 첫 웹페이지</h1>
<button onclick="hey_get()">GET버튼</button>
<button onclick="hey_post()">POST버튼</button>
</body>
</html>
app.py
from flask import Flask, render_template, request,jsonify
app = Flask(__name__)
@app.route('/')
def home():
return render_template('index.html')
@app.route('/test', methods=['GET'])
def test_get():
title_receive = request.args.get('title_give')
print("get : "+title_receive)
return jsonify({'result':'success', 'msg': '이 요청은 GET!'})
@app.route('/test', methods=['POST'])
def test_post():
title_receive = request.form['title_give']
print("post : "+title_receive)
return jsonify({'result':'success', 'msg': '이 요청은 POST!'})
if __name__ == '__main__':
app.run('0.0.0.0',port=5000,debug=True)| [웹개발 종합반 2주차] 회고록 WIL (0) | 2022.02.11 |
|---|---|
| [웹개발 종합반 1주차] 회고록 (0) | 2022.02.11 |
| [파이썬]Flask 시작 - 서버만들기 (0) | 2022.01.25 |
| [파이썬] 텍스트 공백지우기, 범위 출력 (0) | 2022.01.25 |
| [파이썬] 배열 - 추가, 배열이 비어있는지 확인 (0) | 2022.01.22 |