function show_comment() {
fetch('/comment').then(res => res.json()).then(data => {
let rows = data['result']
$('#comments').empty()
rows.forEach((a) => {
let comment = a['comment']
let id = a['_id'];
let date = a['date'];
let writer = a['writer'];
let temp_html = `<div id="comment-one" class="comment-one">
<div class="comment-info">
<span>${writer}</span>
<span>${date}</span>
</div>
<div class="comment-text">
${comment}
</div>
<div class="comment-button">
<button id="comment-update">수정</button>
<buttontoken interpolation">${id})">삭제</button>
</div>
</div>`
$('#comments').append(temp_html)
})
})
}
@app.route("/comment", methods=["POST"])
def comment_post():
comment_receive = request.form['comment_give']
date_receive = request.form['date_give']
# writer = request.form['writer_give']
comment_list = list(db.comment.find({}, {'_id': False}))
count = len(comment_list) + 1
doc = {
'writer': '작성자', #작성자 받아오기
'name': '캠핑장이름',
'num': count, #댓글 등록 시, db에서 특정 댓글을 찾기 위해 'num' 이라는 고유 값 부여
'comment': comment_receive,
'date' : date_receive
}
db.comment.insert_one(doc)
return jsonify({'msg': '댓글이 저장되었습니다'})
@app.route('/comment/<comment_id>', methods=["DELETE"])
def delete_comment(comment_id):
db.comment.delete_one({"_id": ObjectId(comment_id)})
return jsonify({"msg": "코멘트가 삭제되었습니다."})
bson.errors.InvalidId: 'undefined' is not a valid ObjectId, it must be a 12-byte input or a 24-character hex string
형식이 잘못되어 전달되는것같음.
function show_comment() {
fetch('/comment').then(res => res.json()).then(data => {
let rows = data['result']
$('#comments').empty()
rows.forEach((a) => {
let comment = a['comment']
let id = a['num'];
let date = a['date'];
let writer = a['writer'];
let temp_html = `<div id="comment-one" class="comment-one">
<div class="comment-info">
<span>${writer}</span>
<span>${date}</span>
</div>
<div class="comment-text">
${comment}
</div>
<div class="comment-button">
<button id="comment-update">수정</button>
<buttontoken interpolation">${id})">삭제</button>
</div>
</div>`
$('#comments').append(temp_html)
})
})
}
@app.route("/comment", methods=["POST"])
def comment_post():
comment_receive = request.form['comment_give']
date_receive = request.form['date_give']
# writer = request.form['writer_give']
comment_list = list(db.comment.find({}, {'_id': False}))
count = len(comment_list) + 1
doc = {
'writer': '작성자', #작성자 받아오기
'name': '캠핑장이름',
'num': count, #댓글 등록 시, db에서 특정 댓글을 찾기 위해 'num' 이라는 고유 값 부여
'comment': comment_receive,
'date' : date_receive
}
db.comment.insert_one(doc)
return jsonify({'msg': '댓글이 저장되었습니다'})
@app.route('/comment/<comment_id>', methods=["DELETE"])
def delete_comment(comment_id):
db.comment.delete_one({"num": int(comment_id)})
return jsonify({"msg": "코멘트가 삭제되었습니다."})