class id 값 찾아서 margin 재설정했을 때 append 되는 박스까지 간격이 넓어지는데 어딜 수정해야하는걸까요ㅠㅠ?? 왜 둘다 넓어지는지 수정을 거듭했는데도 모르겠어요 명령어는 원복시킨 상태구 margin값만 재부여한 상태 코드로 첨부드립니다.
그리고 실행 후에 몽고db는 제대로 올라오는데 페이지 내에서 append와 show 가 제대로 수행되지않는 원인을 찾지 못하겠어요 ㅠㅠ
*클라이언트
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"></script>
<link href="https://fonts.googleapis.com/css2?family=Gowun+Dodum&display=swap" rel="stylesheet">
<title>상세 페이지</title>
<style>
* {
font-family: 'Gowun Dodum', sans-serif;
}
.gomain {
background-color: transparent;
width: 230px;
height: 65px;
margin: 50px;
color: white;
background-image: url("https://raw.githubusercontent.com/MIINII/sparta_chapter1/c756999647e02db5373558b5624842c89a46c6c3/img/logo/logo.png");
background-size: cover;
background-position: center;
}
.commentbox {
width: 95%;
max-width: 700px;
padding: 20px;
box-shadow: 0px 0px 10px 0px lightblue;
margin: 350px auto;
}
.mycomment {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
}
.mycomment > input {
width: 70%;
}
.commentbox > li {
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
margin-bottom: 10px;
min-height: 48px;
}
.commentbox > li > h2 {
max-width: 75%;
font-size: 20px;
font-weight: 500;
margin-right: auto;
margin-bottom: 0px;
}
.commentbox > li > h2.done {
text-decoration: line-through
}
</style>
<script>
$(document).ready(function () {
show_comment();
});
function show_comment() {
$('#comment-list').empty()
$.ajax({
type: "GET",
url: "/comment",
data: {},
success: function (response) {
let rows = response['comments']
for (let i = 0; i < rows.length; i++) {
let comment = rows[i]['comment']
let num = rows[i]['num']
let done = rows[i]['done']
let temp_html = ``
if (done == 0) {
temp_html = `<li>
<h2>✅ ${comment}</h2>
<button onclick="done_comment(${num})" type="button" class="btn btn-outline-primary">✕</button>
</li>`
} else {
temp_html=`<li>
<h2 class="done">✅ ${comment}</h2>
<button onclick="undo_comment(${num})" type="button" class="btn btn-outline-danger">취소</button>
</li>`
}
$('#comment-list').append(temp_html)
}
}
});
}
function save_comment() {
let comment = $('#comment').val()
$.ajax({
type: "POST",
url: "/comment",
data: {comment_give: comment},
success: function (response) {
alert(response["msg"])
window.location.reload()
}
});
}
function done_comment(num) {
$.ajax({
type: "POST",
url: "/comment/done",
data: { num_give:num },
success: function (response) {
alert(response["msg"])
window.location.reload()
}
});
}
function undo_comment(num){
$.ajax({
type: "POST",
url: "/comment/undo",
data: {num_give: num},
success: function (response) {
alert(response["msg"])
window.location.reload()
}
});
}
</script>
</head>
<body>
<div class="gomain">
</div>
<div class="commentbox">
<div class="mycomment">
<input id="comment" class="form-control" type="text" placeholder="이루고 싶은 것을 입력하세요">
<button onclick="save_comment()" type="button" class="btn btn-outline-primary">기록하기</button>
</div>
</div>
<div class="commentbox" id="comment-list">
</div>
</body>
*서버
from flask import Flask, render_template, request, jsonify
app = Flask(__name__)
from pymongo import MongoClient
import certifi
ca = certifi.where()
client = MongoClient('mongodb+srv://test:sparta@cluster0.kezxt6m.mongodb.net/Cluster0?retryWrites=true&w=majority', tlsCAFile=ca)
db = client.dbsparta
@app.route('/')
def home():
return render_template('detail.html')
@app.route("/comment", methods=["POST"])
def comment_post():
comment_receive = request.form['comment_give']
comment_list = list(db.comment.find({}, {'_id': False}))
count = len(comment_list) + 1
doc = {
'num':count,
'comment':comment_receive,
'done':0
}
db.comment.insert_one(doc)
return jsonify({'msg': '등록을 완료하였습니다.'})
@app.route("/comment/done", methods=["POST"])
def comment_done():
num_receive = request.form['num_give']
db.comment.update_one({'num': int(num_receive)}, {'$set': {'done': 1}})
return jsonify({'msg': '등록을 완료하였습니다.'})
@app.route("/comment", methods=["GET"])
def comment_get():
comment_list = list(db.comment.find({}, {'_id': False}))
return jsonify({'comment': comment_list})
@app.route("/comment/undo", methods=["POST"])
def comment_undo():
num_receive = request.form['num_give']
db.comment.update_one({'num': int(num_receive)}, {'$set': {'done': 0}})
return jsonify({'msg': '삭제를 완료하였습니다.'})
if __name__ == '__main__':
app.run('0.0.0.0', port=4000, debug=True)