커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
4주차 4강 get,post 요청을 했는데 콘솔에 반응이 없어요
undefined주차
북마크
이*련
댓글
5
추천
0
조회수
29
조회수
29
답변 완료


4강에서 버튼을 누르면 함수 hey가 실행되면서 consol창에 뭐가 떠야하는데, 버튼을 눌러도 아무런 반응이 없습니다ㅠㅠ

app.py에서 파일을 저장하고 실행을 누르면 app이 병렬로 실행될 수 없다고 뜨는데 이 문제와 관련이 있는 건가요?




스파르타 즉문즉답


스파르타 즉문즉답






-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(title_receive)
   return jsonify({'result':'success', 'msg': '이 요청은 GET!'})

@app.route('/test', methods=['POST'])
def test_post():
   title_receive = request.form['title_give']
   print(title_receive)
   return jsonify({'result':'success', 'msg': '요청을 잘 받았습니다.'})

if __name__ == '__main__':
    app.run('0.0.0.0', port=5000, debug=True)


-index.html

<!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(){
            $.ajax({
                type: "POST",
                url: "/test",
                data: {title_give: '봄날은간다'},
                success: function (response) {
                    console.log(response)
                }
            })
        }
    </script>

</head>
<body>
    <h1>나의 첫 웹페이지</h1>
    <button onclick="hey">버튼을 만들자</button>

</body>
</html>





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