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



get방식으로 전체 데이터 가져오려고 하는데 안됩니다..어느 부분이 잘못된걸까요 ㅠㅠ?


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

스파르타 즉문즉답




작성한 코드 및 에러 메세지

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

from pymongo import MongoClient
client = MongoClient('mongodb+srv://test1:sparta@cluster0.5ju0bxd.mongodb.net/?retryWrites=true&w=majority')
db = client.dbsparta

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

@app.route("/project01", methods=["POST"])
def comment_post():
    comment_receive = request.form['comment_give']

    doc = {
        'comment': comment_receive
    }
    db.project01.insert_one(doc)

    return jsonify({'msg': '후기 등록 완료!'})

@app.route("/project01", methods=["GET"])
def comment_get():
    comment_list = list(db.project01.find({}, {'_id': False}))
    return jsonify({'comment': comment_list})



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



<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
====================================================================================================
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>1주차 프로젝트</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

    <style>
        .title {
            background-color: cornflowerblue;
            background-image: url("");
            background-position: center;
            background-size: auto;

            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
        }

        .postbox {
            width: 95%;
        }

        .btns {
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
        }
    </style>

    <script>
        // function savebtn() {
        //     alert('저장되었습니다');
        // }
        // function cancelbtn() {
        //     alert('취소되었습니다')
        // }

        $(document).ready(function () {
            show_commentList();
        });

        function savebtn() {
            let comment = $('#comment').val()

            $.ajax({
                type: "POST",
                url: "/project01",
                data: {'comment_give' : comment},
                success: function (response) {
                    alert(response["msg"])
                    window.location.reload()
                }
            });
        }

        function show_commentList() {
            $.ajax({
                type: 'GET',
                url: '/project01',
                data: {},
                success: function (response) {
                    let rows = response['comment']
                    for (let i = 0; i < rows.length; i++) {
                        let comment = rows[i]['comment']

                        console.log(response)

                        let temp_html = `<div class="list-box">
                                            <div class="input-group">
                                                <span class="input-group-text">닉네임</span>
                                                <textarea class="form-control" aria-label="With textarea">${comment}</textarea>
                                        </div>`
                        $('#list-box').append(temp_html)
                    }
                }
            });
        }
    </script>
</head>

<body>
<div class="title">
    <h1>title</h1>
</div>

<div class="postbox"
    <div class="form-floating">
        <textarea class="form-control" placeholder="Leave a comment here" id="comment"
                  style="height: 100px"></textarea>
        <label for="floatingTextarea2">Comments</label>
    </div>

    <div class="btns">
        <button onclick="savebtn()" type="button" class="btn btn-light">저장</button>
        <button onclick="cancelbtn()" type="button" class="btn btn-dark">취소</button>
    </div>
</div>

<div id="listbox">
    <div class="input-group">
        <span class="input-group-text">닉네임</span>
        <textarea class="form-control" aria-label="With textarea">${comment}</textarea>
    </div>
    <div class="input-group">
        <span class="input-group-text">닉네임</span>
        <textarea class="form-control" aria-label="With textarea"></textarea>
    </div>
    <div class="input-group">
        <span class="input-group-text">닉네임</span>
        <textarea class="form-control" aria-label="With textarea"></textarea>
    </div>
</div>

</body>
</html>





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