커뮤니티
포인트
로딩중
쿠폰
내 강의실
국비 신청 내역
수강권
증명서
숙제 피드백
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
GET 요청시 404 오류
[왕초보] 비개발자를 위한, 웹개발 종합반 (프로그래밍 실무, 풀스택)
4주차
북마크
이*웅
댓글
6
추천
0
조회수
70
조회수
70
답변 완료


강의내용대로 버튼 클릭시 콘솔에 response가 나와야 되는데 404에러가 발생하여, ajax url 부분에 localhost:5000으로 변경하여 입력하였는데 cors 에러가 발생합니다 어떻게 처리하면 좋을까요?

from flask import Flask, render_template, request, jsonify
app = Flask(__name__)

@app.route('/')
def home():
   return render_template('index.html')

@app.route('/mypage')
def mypage():
   return 'This is Mypage!'

@app.route('/test', methods=['GET'])
def test_get():
   title_receive = request.args.get('title_give')
   print(title_receive)
   return jsonify({'result':'success', 'msg': '이 요청은 GET!'})

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


<!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: "GET",
            url: "localhost:5000/test?title_give=봄날은간다",
            data: {},
            success: function (response) {
                console.log(response)
            }
        })
    }
    </script>
</head>
<body>
    <h1>나의 첫 웹페이지</h1>
    <button onclick="hey()">버튼을 만들자</button>
</body>
</html>





스파르타 즉문즉답스파르타 즉문즉답







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