카테고리 없음

[4주차]스파르타코딩클럽 웹개발 종합반 마지막

tft4rollz 2022. 10. 24. 17:40

4-14 4주차 끝 & 숙제 

마지막으로 주차 마지막에 계속 숙제로 내주신 방명록 작성이다.

1) 응원 남기기(POST): 정보 입력 후 '응원 남기기' 버튼클릭 시 주문목록에 추가

2) 응원 보기(GET): 페이지 로딩 후 하단 응원 목록이 자동으로 보이기

 

제일 먼저 POST 방식부터 했다.

app.py 는 이렇게 만들었고

@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.homeworks.insert_one(doc)
    return jsonify({'msg': '전송 완료!'})

index.html도 저번에 했던 작업물들 참고해가면서 만들었다.

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()
}
})
}

다행히 두번만에 무사히 데이터 잘 넘어가서 바로 GET 방식도 이전 작업물 참고하며 만들었다.

app.py

@app.route("/homework", methods=["GET"])
def homework_get():
    fan_user = list(db.homeworks.find({}, {'_id': False}))

    return jsonify({'homeworks': fan_user})

index.html

function show_comment(){
$.ajax({
type: "GET",
url: "/homework",
data: {},
success: function (response) {
    let rows = response["homeworks"]
    for (let i = 0 ; 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)

    }
}
});
}

프로젝트 세개를(화성땅 , 스파르타피디아 , 숙제)  하니 처음보다는 훨씬 뭘 타이핑해야할지 생각도 되고

여러모로 많이 적응이 된거같다 ㅎㅎㅋㅋ 스무스하게 끝났다.

 

이제 마지막 5주차를 들을 시간이다.

5주차는 이제 내가 만든 홈페이지를 다른 사람들도 볼 수 있게 하는 작업을 한다고 하는데 기대 반 긴장 반 상태다 ㅠㅠㅎ

얼른 적응해서 11월에 시작하는 내일배움캠프때 다른 사람들한테 민폐 끼치지 않아야겠다!