
포스팅 되고 있도록 할수는 있겠는데 생각해보니 중복신청자가 생길수 있겠더라구요
신청자를 한 날짜에 한 사람만 하려고 하는데 어떨까요?

작성한 코드 및 에러 메세지
# 라이브러리 설치 ( flask,dnspython, pymongo : DB관련)
# ( requests,bs4 : 크롤링관련)
from flask import Flask, render_template, request, jsonify
app = Flask(__name__)
from pymongo import MongoClient
client = MongoClient('mongodb+srv://ooalaoo:wooju1031@cluster0.ytgitra.mongodb.net/?retryWrites=true&w=majority')
db = client.dbsparta
@app.route('/')
def home():
return render_template('index.html')
@app.route("/bible", methods=["POST"])
def bible_post():
name_receive = request.form['name_give']
readdate_receive = request.form['readdate_give']
txtMobile1_receive = request.form['txtMobile1_give']
txtMobile2_receive = request.form['txtMobile2_give']
doc = {
'name': name_receive,
'readdate': readdate_receive,
'txtMobile1': txtMobile1_receive,
'txtMobile2': txtMobile2_receive
}
db.bible.insert_one(doc)
return jsonify({'msg': '댓글저장완료!'})
@app.route("/bible", methods=["GET"])
def bible_get():
all_list = list(db.bible.find({}, {'_id': False}))
return jsonify({'read-all':all_list})
if __name__ == '__main__':
app.run('0.0.0.0', port=5000, debug=True)
#index.html
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<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>
<title>Voice of God 성경일독 신청</title>
<link href="https://fonts.googleapis.com/css2?family=Noto+Serif+KR:wght@200;300;400;500;600;700;900&display=swap" rel="stylesheet"><style>
* {
font-family: 'Noto Serif KR', serif;
}
.mypic {
width: 100%;
height: 200px;
background-image: linear-gradient(0deg, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url('https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&fname=https%3A%2F%2Fk.kakaocdn.net%2Fdn%2FJMYHB%2FbtrQ8HJ2YOF%2FPqHd1ykkfQx5zKFKwwgAXK%2Fimg.jpg');
background-position: center 30%;
background-size: cover;
color: white;
display: flex;
flex-direction: column;
justify-content: center;
}
.bible {
width: 1420px;
height: 700px;
background-image: linear-gradient(0deg, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0)), url('https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&fname=https%3A%2F%2Fk.kakaocdn.net%2Fdn%2FwcEqg%2FbtrReGoRKwc%2F92dNsHFkzkzLMTuPMke9hK%2Fimg.png');
background-position: center 0%;
background-size: cover;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
margin: 10px auto 10px auto;
}
.mypost {
width: 95%;
max-width: 500px;
margin: 20px auto 20px auto;
box-shadow: 0px 0px 3px 0px black;
padding: 20px;
}
.form-floating-phone > form {
width: 700px;
}
.form-floating-phone > form > input {
width: 50px;
max-width: 200px;
margin: 10px 10px 10px 10px;
}
.mypost > button {
margin-top: 15px;
}
.mycards {
width: 95%;
max-width: 500px;
margin: auto;
flex-direction: column;
}
.mycards > .card {
margin-top: 10px;
margin-bottom: 10px;
}
</style><script>
$(document).ready(function(){
set_temp()
show_comment()
});
function set_temp(){
$.ajax({
type: "GET",
url: "http://spartacodingclub.shop/sparta_api/weather/seoul",
data: {},
success: function (response) {
$('#temp').text(response['temp'])
}
})
}
function save_comment(){
let readdate = $('#readdate').val()
let txtMobile1 = $('#txtMobile1').val()
let txtMobile2 = $('#txtMobile2').val()
let name = $('#name').val()
$.ajax({
type: 'POST',
url: '/bible',
data: {name_give:name, txtMobile1_give:txtMobile1, txtMobile2_give:txtMobile2, readdate_give:readdate},
success: function (response) {
alert(response['msg'])
window.location.reload()
}
})
}
function show_comment(){
$.ajax({
type: "GET",
url: "/bible",
data: {},
success: function (response) {
let rows = response['read-all']
for (let i = 0; i < rows.length; i++) {
let name = rows[i]['name']
let readdate = rows[i]['readdate']
let txtMobile2 = rows[i]['txtMobile2']
let temp_html = `<div class="card">
<div class="card-body">
<blockquote class="blockquote mb-0">
<p>${name}님이 ${readdate}에 성경통독을 신청하셨습니다.</p>
<footer class="blockquote-footer">010-****-${txtMobile2}</footer>
</blockquote>
</div>
</div>`
$('#comment-list').append(temp_html)
}
}
});
}
</script>
</head>
<body><div class="mypic"><h1>Voice of God 성경일독 신청</h1><p>현재기온: <span id="temp">36</span>도</p></div><div class="bible-explain"><p>편집하고 유튜브에 올릴시간이 필요한 관계로 7일전에 메일로 보내주셔야만 유튜브에 업로드가 가능합니다 ( 메일주소 : seonu1031@naver.com )</p><p>그때까지 보내주지지 않으시면 자동취소가 됩니다</p><p>매달 보내주신분들중 3분을추첨하여 커피쿠폰을 보내드립니다</p>
</div><div class="bible"></div><div class="mypost"><div class="form-floating mb-3"><input type="text" class="form-control" id="name" placeholder="url"><label for="floatingInput">신청인</label></div><div class="form-floating data"><input type="date" class="form-control" id="readdate" min="2023-01-01" max="2023-12-31" placeholder="url2"><label for="floatingInput">날짜</label></div><div class="form-floating-phone"><label for="floatingInput">전화번호</label><select id="txtMobile1"><option value="">::선택::</option><option value="010">010</option></select><input type="text" id="txtMobile2" size="4" /><input type="text" id="txtMobile3" size="4" /><p> </p>
</div>
<button onclick="save_comment()" type="button" class="btn btn-dark">신청하기</button></div><div class="mycards" id="comment-list"><div class="card"><div class="card-body">
</div></div></div>
</body>
</html>
고민해본 코드는
save_comment function 에서
alert(response['msg'])
- >
if readdate in rows['readdate']:
print('신청자가 있습니다.')
else:
alert(response['msg'])
ㄹ로바꿨더니 아예 포스팅 자체가 안되어버리더라구요 해결방법이 있을까요??ㅜ
ㅎ혹시 포스팅 되는 것들도 날짜순에 따라 오른차순이나 내림차순으로 정렬할수도있나요??
