어제보다는 조금 나은느낌?
오늘은 어제 팀원분들이 거의 다 만들어놓은거 상의하면서 수정할거 고쳤음.
12시간씩 html하고 mongodb 연결하는거 쳐다보고있으니까 사알짝 느낌은 온 느낌?
뼈대 있으니까 수정하고 기능 추가하려는 노력은 해봤던 하루였다.
댓글 작성하고 삭제하는거 ㄹㅇ 개헬이었음.
이거 나중에 꼭 다시 한번 보고싶네.
-공부한 것-
post.html
function save_comment() {
let comment = $('#comment').val()
let post_id = {{ post_id}}
if (comment.length == "") {
alert('댓글을 입력 하세요!')
return true;
}
$.ajax({
type: "POST",
url: "/comment",
data: {comment_give: comment, post_id_give: post_id, },
success: function (response) {
alert(response["msg"])
window.location.reload()
}
});
}
app.py
@app.route("/comment", methods=["POST"])
def comment_post():
comment_receive = request.form['comment_give']
id_receive = int(request.form['post_id_give'])
comment_list = list(db.comment.find({}, {'_id': False}))
count = len(comment_list) + 1
doc = {
'comment': comment_receive,
'num': count,
'post_id': id_receive,
}
db.comment.insert_one(doc)
return jsonify({'msg': '등록 완료!'})
@app.route("/comment", methods=["GET"])
def comment_get():
comment_list = list(db.comment.find({}, {'_id': False}))
return jsonify({'comments': comment_list})
@app.route("/comment/num", methods=["POST"])
def comment_del():
num_receive = request.form['num_give']
comment_receive = request.form['comment_give']
db.comment.delete_one({'num': int(num_receive), 'comment': comment_receive})
return jsonify({'msg': '삭제 완료!'})
댓글 쪽 코드인데 두고두고 좀 봐야겠다.