커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
4주차 숙제 post 방식에서 DB저장에서 닉네임과 코멘트 출력이 안돼요
undefined주차
북마크
김*선
댓글
8
추천
0
조회수
9
조회수
9
답변 완료

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

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



mongoDB에서 데이터베이스 저장은 되는데 코멘트와 입력한 닉네임이 출력되지 않고 이미지와 같이 나와요


스파르타 즉문즉답





app.py

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

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

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

@app.route("/homework", methods=["POST"])
def homework_post():
    name_receive = request.form['name_give']
    comment_receive = request.form['comment_give']

    doc = {
        'name':name_receive,
        'comment':comment_receive
    }

    db.homework.insert_one(doc)

    return jsonify({'msg':'POST 응원 완료!'})

index_html

function save_comment(){
    let name = $('#name').val()
    let comment = $('#comment').val()
    $.ajax({
        type: 'POST',
        url: '/homework',
        data: {name_give:name, comment_give:comment},
        success: function (response) {
            alert(response['msg'])
            window.location.reload()
        }
    })
}

ㅍ포스트 입력 시 정상적으로 알럿 메시지 노출되는데 DB설정에서 제가 잘못한 걸까요?

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