[app.py]
## API 역할을 하는 부분
@app.route('/review', methods=['POST'])
def write_review():
title_receive = request.form['title_give']
author_receive = request.form['author_give']
review_receive = request.form['review_give']
doc = {
'title': title_receive,
'author': author_receive,
'review': review_receive
}
db.bookreview.insert_one(doc)
print(sample_receive)
return jsonify({'msg': '리뷰가 성공적으로 작성되었습니다.'})
function makeReview() {
let title = $("#title").val();
let author = $("#author").val();
let review = $("#bookReview").val();
$.ajax({
type: "POST",
url: "/review",
data: {title_give: title, author_give: author, review_give: review},
success: function (response) {
alert(response["msg"]);
window.location.reload();
}
})
}
- 새로고침하면 이 요청은 GET!라고 뜸