커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
질문
undefined주차
북마크
임*빈
댓글
3
추천
0
조회수
10
조회수
10
답변 완료

* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.

* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.



스파르타 즉문즉답

post 연결 확인하려고 나는 버튼 눌렀는데 오류가 뜹니다!


<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=['POST'])

def test_post():

title_receive = request.form['title_give']

print(title_receive)

return jsonify({'result':'success', 'msg': '이 요청은 POST!'})


if __name__ == '__main__':

app.run('0.0.0.0',port=5001,debug=True)




<index.html>

<!DOCTYPE html>

<html lang="en">


<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

<title>Document</title>


<script>

function hey() {

let formData = new FormData();

formData.append("title_give", "블랙팬서");


fetch("/test", { method: "POST", body: formData }).then(res => res.json()).then(data => {

console.log(data)

})

}

</script>

</head>


<body>

<hi>제목을 입력합니다</hi>

<button onclick="hey()">나는 버튼!</button>

</body>


</html>계신 화면 전체를 캡처해 주시면, 튜터님들이 빠르게 상황을 이해할 수 있어요.







취소
 공유
취소
댓글 0
댓글 알림
나의얼굴