본문 바로가기
개발일지

나홀로 쇼핑몰(스파르타)

by crescent88 2022. 5. 14.

4주차 과제를 제출했다. 

뭔가 다른 점이 있는데 왜 다른건지 어떤부분이 다른건지 잘 모르겠다

하지만 일단 입력까지는 문제가 없다. 

 

거의 베끼는 식이었지만 많이 만들고 더 연습하다 보면 익숙해지고 이해 할 수 있지 않을까 기대해본다. 

 

조금 어려웠지만 그만큼 성취감이 느껴진다. 

수료하고나서 이제는 정말 무엇을 만들 수 있을지 기대된다. 

 

 

from flask import Flask, render_template, jsonify, request

app = Flask(__name__)

from pymongo import MongoClient
client = MongoClient('localhost', 27017)
db = client.dbhomework


## HTML 화면 보여주기
@app.route('/')
def homework():
    return render_template('index.html')


# 주문하기(POST) API
@app.route('/order', methods=['POST'])
def save_order():
    name_receive = request.form['name_give']
    count_receive = request.form['count_give']
    address_receive = request.form['address_give']
    phone_receive = request.form['phone_give']

    doc = {
        'name': name_receive,
        'count': count_receive,
        'address': address_receive,
        'phone': phone_receive
    }
    db.aloneshoping.insert_one(doc)

    return jsonify({'msg': '주문완료!'})


# 주문 목록보기(Read) API
@app.route('/order', methods=['GET'])
def view_orders():
    orders = list(db.aloneshoping.find({}, {'_id': False}))
    return jsonify({'all_orders':orders})


if __name__ == '__main__':
    app.run('0.0.0.0', port=5000, debug=True)
<!doctype html>
<html lang="en">

<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
          integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
            integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
            crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
            integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
            crossorigin="anonymous"></script>

    <title>스파르타코딩클럽 | 부트스트랩 연습하기</title>
    <link href="https://fonts.googleapis.com/css2?family=Jua&family=Nanum+Pen+Script&family=Noto+Serif+KR:wght@200&display=swap" rel="stylesheet">
    <style>
        * {
            font-family: 'Jua', sans-serif;
        }
        .image {
            width: 400px;
            height: 250px;

            background-image: url("data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAoHCBISERISEhIRERERERESERERERERERESGBgZGRgUGBgcIS4lHB4rHxgYJjgmKy8xNTU1GiQ7QDs0Py40NTEBDAwMEA8QGhISGjEhISExNDE0NDQ0NDQ0NDQ0NDQ0NDE0MTQxNDQ0NDQ0NDQ0MTQ0NDQ0NDQ0NDQxNDQ0NDQ0Mf/AABEIAMIBBAMBIgACEQEDEQH/xAAbAAABBQEBAAAAAAAAAAAAAAACAAEDBQYEB//EAD8QAAIBAgMFBgMHAgMJAQAAAAECAAMRBAUhBhIxQVETImFxgZEywdEjQlJicqGxgvAzQ7IWJDRzkqLC4fEV/8QAGgEBAQADAQEAAAAAAAAAAAAAAAECBAUDBv/EADERAAIBAwIDBgYBBQEAAAAAAAABAgMEESExEhNBBSJRsdHwMmFxocHhMyQlQ4GRI//aAAwDAQACEQMRAD8A60STosFVkyrKQdRJlEZRCAkA4EMCMIUFHAhCMBCAgD2jgRAQgIAwEK0cCOJANCAjxCAK0e0cCOBBcDWitHtFAwNaK0K0a0EGtGtCIjWgDWjWhWiIlAFoJEMiMRAI4JElIgEQQiIkbCTE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tH8v6IsKtIU6QQaAAKB4CcOEp7z+C6mS4iuar7qcBoTyUfWDisdTwyWuGe2ijkerT3hByeEji1akc8ybwl5lRtVVBdVHFdT8oeymHN3qEaW3F8ep/YStwuFfF1CxuELXd+vgJscPRWmgVRYAWAE2qs1CHLWr6mvb0pVavPmsLoiYmMTGJjEzTOkPeCTFGMoGMRMYmCTAETIyY5MAmCCaRsY7GRu0oG3opETHjBMkaNJlacaPJ0aQHWDCBnOrSUGCkwMMGQAwwYBKDHvIwYQaChgwgZGDHBkBJeODAvHBgEl495HeK8AgzDD9ohTgG4nwkjUQQo+6lrDyGkkvFeCYWcnGuBUOajd5rWF+Q6CBiu0YXckIOCJxPhed5gsLwVtvcoauJxLDcpU+zXqeJ8zxgYXISx3qzFue6NF9es0ISFPTmyxhaL5GurenxcTWX89f0BRoqgAUAAcAJJGvGvPM2ByY141414A94xMEtG3pQOTBJjEwCYIImCxiJgM0pMjM0hZoTNIHeAOWikG9GggKSdIopComWSrFFBQlhiNFADEMRRQAo4iikASx4ooA4iiigDxRRQB4oooAxjRRQBRoooINBMaKCigmKKUAmAYooALQDFFBiQvOd4opQQxRRQQ//9k=");
            background-size: cover;
            background-position: center;

            margin: auto;
        }

        .wrap {
            margin: 10px auto;
            width: 400px;
            height: 800px;
        }

        .btn-primary {
            margin: auto;
            display: block;

        }

        .title {
            font-size: 25px;
            margin-top: 14px;
            font-weight: bold;

        }

        .comment {
            font-size: 14px;
        }

        .rate {
            color: blue;
        }

        .table {
            width: 400px;
            margin : auto;
        }
    </style>
    <script>
        $(document).ready(function () {
            q1()
            showorder()
        });

        function makeorder() {
            let name = $('#name').val()
            let count = $('#inputGroupSelect01').val()
            let address = $('#address').val()
            let phone = $('#phone').val()

            $.ajax({
                type: "POST",
                url: "/order",
                data: {name_give:name, count_give:count, address_give:address, phone_give:phone},
                success: function (response) {
                    alert(response["msg"]);
                    window.location.reload();
                }
            })
        }

            function showorder() {
                $.ajax({
                    type: "GET",
                    url: "/order",
                    data: {},
                    success: function (response) {
                        let orders = response['all_orders']
                        for (let i = 0; i < orders.length; i++) {
                            let name = orders[i]['name']
                            let count = orders[i]['count']
                            let address = orders[i]['address']
                            let phone = orders[i]['phone']

                            let temp_html = `
                                            <tr>
                                              <th scope="row">${name}</th>
                                              <td>${count}</td>
                                              <td>${address}</td>
                                              <td>${phone}</td>
                                            </tr>`
                            $('#orders').append(temp_html)
                        }
                    }
                })
            }


        function q1() {
            $.ajax({
                type: "GET",
                url: "http://spartacodingclub.shop/sparta_api/rate",
                data: {},
                success: function (response) {
                    let rate = response['rate']
                    let temp_html = `<p>달러-원 환율: ${rate}</p>`
                    $('#rate').append(temp_html)

                }
            })
        }
    </script>

</head>

<body>
    <div class="wrap">
        <div class="image"></div>
        <p class="title">치실을 팝니다<span style="font-size:10px;">가격: 3,000원/개</span></p>
        <p class="comment">이 치실은 사실 특별한 힘을 가지고 있어요. 치실을 들고 이 사이에 끼우기만 성공하면 마치 스케일링을 받은것과 같은 효과가 일어납니다. 딸기향도 나요</p>
        <div onclick="q1()" class="rate" id="rate"></div>
        <div class="input-group mb-3">
            <div class="input-group-prepend">
                <span class="input-group-text" id="basic-addon1">주문자 이름</span>
            </div>
            <input type="text" class="form-control" id="name" aria-describedby="basic-addon1">
        </div>
        <div class="input-group mb-3">
            <div class="input-group-prepend">
                <label class="input-group-text" for="inputGroupSelect01">수량</label>
            </div>
            <select class="custom-select" id="inputGroupSelect01">
                <option selected>-- 수량을 선택하세요 --</option>
                <option value="1">1</option>
                <option value="2">2</option>
                <option value="3">3</option>
            </select>
        </div>
        <div class="input-group mb-3">
            <div class="input-group-prepend">
                <span class="input-group-text" id="basic-addon1">주소</span>
            </div>
            <input type="text" class="form-control" id="address" aria-describedby="basic-addon1">
        </div>
        <div class="input-group mb-3">
            <div class="input-group-prepend">
                <span class="input-group-text" id="basic-addon1">전화번호</span>
            </div>
            <input type="text" class="form-control" id="phone" aria-describedby="basic-addon1">
        </div>
        <button onclick="makeorder()" type="button" class="btn btn-primary">주문하기</button>
    </div>
    <table class="table">
      <thead>
        <tr>
          <th scope="col">이름</th>
          <th scope="col">수량</th>
          <th scope="col">주소</th>
          <th scope="col">전화번호</th>
        </tr>
      </thead>
      <tbody id="orders">
      </tbody>
    </table>
</body>

</html>