
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
안녕하세요!
강의 4-8보면서 했는데
get 실행할때 튜터님이 콘솔창에 찍고 페이지 들어가서 콘솔창에 orders에 클릭해서 보면 db에 저장한게 보이거든요?
근데 저는 콘솔창에 orders는 있는데 db에 저장한게 안보여요.
이건뭐죠??
post 실행할때는 db에 저장된걸 확인했어요
@app.route("/wines", methods=["GET"])
def web_wines_get():
order_list = list(db.wines.find({}, {'_id': False}))
return jsonify({'orders': 'order_list'})
$(document).ready(function () {
show_order();
});
function show_order() {
$.ajax({
type: 'GET',
url: '/wines',
data: {},
success: function (response) {
console.log(response)
}
});
}


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<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>
<title>상품 목록 페이지</title>
<link href="https://fonts.googleapis.com/css2?family=Nanum+Pen+Script&display=swap" rel="stylesheet">
<style>
* {
font-family: 'Nanum Pen Script', cursive;
}
.mytitle {
background-color: #800080;
height: 180px;
text-align: center;
border-radius: 10px;
font-size: 50px;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
/*.myimg {*/
/* padding: 10px;*/
/* width: 150px;*/
/* height: 110px;*/
/* border-radius: 20px;*/
/*}*/
.myrecord {
width: 150px;
margin: auto;
margin-top: 100px;
}
.card {
width: 500px;
margin: auto;
margin-top: 20px;
}
.btn-outline-secondary {
padding: 8px 10px 8px 8px;
font-size: 21px;
border-radius: 50px;
}
.mywriting {
margin: 10px 10px 10px 10px;
font-size: 100px;
}
.winecards {
max-width: 1500px;
width: 95%;
margin: 30px auto 10px auto;
}
.cardimg {
margin: auto;
}
.card-title {
font-size: 60px;
}
.mybtns {
margin-top: 10px;
}
.card-warp{
max-width: 500px;
width: 95%;
margin: 20px auto 0px auto;
box-shadow: 0px 0px 3px 0px gray;
display: none;
}
</style>
<script>
$(document).ready(function () {
show_order();
});
function show_order() {
$.ajax({
type: 'GET',
url: '/wines',
data: {},
success: function (response) {
console.log(response)
}
});
}
function save_order() {
let star = $('#star').val()
let comment = $('#comment').val()
$.ajax({
type: 'POST',
url: '/wines',
data: {star_give: star, comment_give: comment},
success: function (response) {
alert(response['msg'])
window.location.reload()
}
});
}
function hey() {
alert('안녕!');
}
function open_card() {
$('#post-box').show()
}
function close_card() {
$('#post-box').hide()
}
</script>
</head>
<body>
<div class="mytitle">
<img class="myimg" src="https://cdn-0.emojis.wiki/emoji-pics/microsoft/wine-glass-microsoft.png"
jsaction="load:XAeZkd;" jsname="HiaYvf" class="n3VNCb KAlRDb"
alt="🍷 Wine Glass Emoji — Meaning, Copy & Paste, Combinations 🍷➡️😋" data-noaft="1"
style="width: 140px; height: 100px; margin: 20px 0px;">
<h1 class="mywriting">나만의 와인은 ? </h1>
</div>
<div class="myrecord" id="record-box">
<p>
<button onclick="open_card()" type="button" class="btn btn-outline-secondary">익명 추천 와인 기록지</button>
</p>
</div>
<div class="card-warp" id="post-box">
<div class="card-body">
<blockquote class="blockquote mb-0">
<div class="input-group mb-3">
<label class="input-group-text" for="star">별점</label>
<select class="form-select" id="star">
<option selected>-- 선택하기 --</option>
<option value="1">⭐</option>
<option value="2">⭐⭐</option>
<option value="3">⭐⭐⭐</option>
<option value="4">⭐⭐⭐⭐</option>
<option value="5">⭐⭐⭐⭐⭐</option>
</select>
</div>
<div class="form-floating">
<textarea class="form-control" placeholder="Leave a comment here" id="comment"
style="height: 100px"></textarea>
<label for="comment">와인 이름 + 코멘트</label>
</div>
<div class="mybtns">
<button onclick="save_order()" type="button" class="btn btn-dark">기록하기</button>
<button onclick="close_card()" type="button" class="btn btn-outline-dark" >닫기</button>
</div>
</blockquote>
</div>
</div>
<div class="winecards">
<div id="wrap" class="row row-cols-1 row-cols-md-3 g-4">
<div class="col">
<div class="card">
<div class="cardimg">
<img class="cardimg" src="https://www.ahiddenvine.com/assets/images/bottle-shot.jpeg"
jsaction="load:XAeZkd;"
jsname="HiaYvf" class="n3VNCb KAlRDb" class="card-img-top"
alt="Realm Cellars 2018 The Absurd Red Napa Valley" data-noaft="1"
style="width: 150px; height: 350px; margin: 0px;" class="card-img-top" alt="...">
</div>
<div class="card-body">
<h1 onclick="hey()" class="card-title">
<button type="button" class="btn btn-outline-secondary">뤠암 업서드</button>
</h1>
<h5><span class="" style="background:#C50D0D;"> </span> 레드 🇺🇸 미국</h5>
<p class="card-text">앱서드는 최고의 빈티지에 뤠암의 다른 와인에 영향을 주지 않고 만들 수 있는 충분한 양의 포도가 있는 특정 해에만 만들어진다. 블렌딩에
사용...</p>
<p> 3,000,000원 /<a
href="https://www.winenara.com/shop/product/product_lists?sh_category1_cd=10000&sh_category2_cd=10100">
매장문의 </a></p>
</div>
</div>
</div>
<div class="col">
<div class="card">
<div class="cardimg">
<img class="cardimg" src="https://www.ahiddenvine.com/assets/images/bottle-shot.jpeg"
jsaction="load:XAeZkd;"
jsname="HiaYvf" class="n3VNCb KAlRDb" class="card-img-top"
alt="Realm Cellars 2018 The Absurd Red Napa Valley" data-noaft="1"
style="width: 150px; height: 350px; margin: 0px;" class="card-img-top" alt="...">
</div>
<div class="card-body">
<h1 onclick="hey()" class="card-title">
<button type="button" class="btn btn-outline-secondary">뤠암 업서드</button>
</h1>
<h5><span class="" style="background:#C50D0D;"> </span> 레드 🇺🇸 미국</h5>
<p class="card-text">앱서드는 최고의 빈티지에 뤠암의 다른 와인에 영향을 주지 않고 만들 수 있는 충분한 양의 포도가 있는 특정 해에만 만들어진다. 블렌딩에
사용...</p>
<p> 3,000,000원 /<a
href="https://www.wine21.com/main.html">
매장문의 </a></p>
</div>
</div>
</div>
<div class="col">
<div class="card">
<div class="cardimg">
<img class="cardimg" src="https://www.ahiddenvine.com/assets/images/bottle-shot.jpeg"
jsaction="load:XAeZkd;"
jsname="HiaYvf" class="n3VNCb KAlRDb" class="card-img-top"
alt="Realm Cellars 2018 The Absurd Red Napa Valley" data-noaft="1"
style="width: 150px; height: 350px; margin: 0px;" class="card-img-top" alt="...">
</div>
<div class="card-body">
<h1 onclick="hey()" class="card-title">
<button type="button" class="btn btn-outline-secondary">뤠암 업서드</button>
</h1>
<h5><span class="" style="background:#C50D0D;"> </span> 레드 🇺🇸 미국</h5>
<p class="card-text">앱서드는 최고의 빈티지에 뤠암의 다른 와인에 영향을 주지 않고 만들 수 있는 충분한 양의 포도가 있는 특정 해에만 만들어진다. 블렌딩에
사용...</p>
<p> 3,000,000원 /<a
href="https://www.winenara.com/shop/product/product_lists?sh_category1_cd=10000&sh_category2_cd=10100">
매장문의 </a></p>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
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.oqyeqew.mongodb.net/Cluster0?retryWrites=true&w=majority', tlsCAFile=ca)
db = client.dbsparta
@app.route('/')
def home():
return render_template('상품 목록 페이지 index.html')
@app.route("/wines", methods=["POST"])
def web_wines_post():
star_receive = request.form['star_give']
comment_receive = request.form['comment_give']
doc = {
'star':star_receive,
'comment':comment_receive
}
db.wines.insert_one(doc)
return jsonify({'msg': '기록 완료!!'})
@app.route("/wines", methods=["GET"])
def web_wines_get():
order_list = list(db.wines.find({}, {'_id': False}))
return jsonify({'orders': 'order_list'})
if __name__ == '__main__':
app.run('0.0.0.0', port=5000, debug=True)
