
몇번을 해봐도 안되요
db에 homework생성이 안됩니다
<import>
from pymongo import MongoClient
client = MongoClient('mongodb+srv://jeongeunkim:sparta@cluster0.euinico.mongodb.net/Cluster0?retryWrites=true&w=majority')
db = client.dbsparta
<db 저장>
@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':'응원 완료!'})
<script>
<script>
$(document).ready(function () {
show_comment()
});
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()
}
})
}
function show_comment() {
$('#comment-list').empty()
$.ajax({
type: "GET",
url: "/homework",
data: {},
success: function (response) {
let rows = response['comments']
for (let i = 0; i < rows.length; i++){
let name = rows[i]['name']
let comment = rows[i]['comment']
let temp_html = `<div class="card">
<div class="card-body">
<blockquote class="blockquote mb-0">
<p>${comment}</p>
<footer class="blockquote-footer">${name}</footer>
</blockquote>
</div>
</div>`
$('#comment-list').append(temp_html)
}
}
});
}
</script>
강의를 다시 보고 또해봐도 디비 저장이 안됩니다
