커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
get post 다 에러 떠요
undefined주차
북마크
연*아
댓글
7
추천
0
조회수
20
조회수
20
답변 완료
스파르타 즉문즉답
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:test@cluster0.u2iw4lb.mongodb.net/Cluster0?retryWrites=true&w=majority', tlsCAFile=ca)
db = client.dbsparta


@app.route('/')
def home():
    return render_template('index.html')


@app.route("/grboy", methods=["POST"])
def homework_post():
    name_receive = request.form['name']
    comment_receive = request.form['comment']

    doc = {
        'name_list': name_receive,
        'comment_list': comment_receive
    }
    db.grboy.insert_one(doc)

    return jsonify({'msg': '응원 남기기 성공!'})


@app.route("/grboy", methods=["GET"])
def homework_get():
    return jsonify({'msg': 'GET 연결 완료!'})


if __name__ == '__main__':
    app.run('0.0.0.0', port=5000, debug=True)





<!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>

    <!--Black+Han+Sans 폰트-->
    <link href="https://fonts.googleapis.com/css2?family=Black+Han+Sans&family=Gowun+Batang&family=Hahmlet&display=swap"
          rel="stylesheet">

    <title>기리보이 팬명록</title>
    <style>

        * {
            font-family: 'Hahmlet', serif;
        }

        /*팬명록 text*/
        .mytitle > h1 {
            font-size: 70px;
            text-align: center
            background-color: lightpink;
        }

        /*서울시 온도 API*/
        #temp {
            font-size: 20px;
        }

        /*헤더영역*/
        .mytitle {
            width: 100%;
            height: 768px;

            background-image: linear-gradient(0deg, rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.7)), url('https://scontent-ssn1-1.xx.fbcdn.net/v/t1.6435-9/93653847_2998553740211630_2308237436301344768_n.jpg?stp=cp0_dst-jpg_e15_p403x403_q65&_nc_cat=111&ccb=1-7&_nc_sid=8024bb&_nc_ohc=DlQ7yHxXoFIAX8O9XdK&_nc_ht=scontent-ssn1-1.xx&oh=00_AT-ZoUhFMw-JL_A_L0DBGVjLceuiSMhfJSZbNjYrhNyo6Q&oe=6321EC6B');
            background-position: center;
            background-size: cover;
            color: whitesmoke;

            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
        }

        .mycheerallbtn {
            display: flex;
            flex-direction: row;
            justify-content: center;
        }

        /*응원남기기 버튼*/
        .mycheerallbtn > button {
            width: 13%;
            font-size: 17px;
            padding: 20px;
            margin: 30px 10px;
            border-radius: 50px;
        }

        /*카드 섹션*/
        .mysection {
            border: 1px solid darkgray;
            width: 35%;
            margin: 50px auto;
            padding: 1%;
            display: none;
        }


        .blockquote > p {
            font-size: 16px;
        }

        .blockquote > :last-child {
            font-size: 15px;
        }

    </style>

    <script>

        $.ajax({
            type: "GET",
            url: "http://spartacodingclub.shop/sparta_api/weather/seoul",
            data: {},
            success: function (response) {
                let temps = response['temp']
                let cloud = response['clouds']

                $('#temp').append('현재 서울시 기온 : ' + temps + '˚' + `<br>` + '강수 확률 : ' + cloud);
                $('#temp').addClass('text-center');
            }
        });

        $(document).ready(function () {
            show_order();
        });

        function show_order() {
            $.ajax({
                type: 'GET',
                url: '/grboy',
                data: {},
                success: function (response) {
                    alert(response['msg'])
                }
            });
        }

        function save_msg() {

            let name = $('#exampleFormControlInput1').val();
            let comment = $('#exampleFormControlTextarea1').val();

            $.ajax({
                type: 'POST',
                url: '/grboy',
                data: {
                    name_list: name, comment_list: comment},
                    success: function (response) {
                        console.log(response['msg'])
                        window.location.reload();
                    }
                });
        }


            function chrbtn() {
                $('#mycard').show();
            }

            function closebtn() {
                $('#mycard').hide();
            }


    </script>
</head>

<body>

<!--헤더 시작-->
<div class="mytitle">
    <h1>기리보이<br/>팬명록💗</h1>
    <p id="temp"></p>
</div>
<!--헤더 끝-->

<!--응원남기기 시작-->
<!--응원남기기 버튼 시작-->
<div class="mycheer">
    <div class="mycheerallbtn">
        <button onclick="chrbtn()" type="button" class="btn btn-outline-danger">응원남기기</button>
        <button onclick="closebtn()" type="button" class="btn btn-outline-danger">닫기</button>
    </div>
    <!--응원남기기 버튼 끝-->
    <div id="mycard" class="mysection">
        <div class="mb-3">
            <label for="exampleFormControlInput1" class="form-label"></label>
            <input type="email" class="form-control" id="exampleFormControlInput1" placeholder="닉네임">
        </div>
        <div class="mb-3">
            <label for="exampleFormControlTextarea1" class="form-label"></label>
            <textarea class="form-control" id="exampleFormControlTextarea1" placeholder="응원댓글" rows="3"></textarea>
        </div>

        <button type="button" onclick="save_msg()" class="btn btn-danger">확인</button>

        <!--댓글 시작-->
        <div class="myfooter">
            <div class="card-body">
                <blockquote class="blockquote mb-0">
                    <p>역시 기리보이!</p>
                    <footer class="blockquote-footer">홍셩팬</footer>
                </blockquote>
            </div>
        </div>
        <!--댓글 끝-->
    </div>
</div>
<!--응원남기기 끝-->

</body>
</html>


취소
 공유
취소
댓글 0
댓글 알림
나의얼굴