커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
웹화면에 데이타 가져오기
undefined주차
북마크
박*열
댓글
5
추천
0
조회수
16
조회수
16
답변 완료


아래 이름 주소 평수에 데이타 조회가 안됩니다.

콘솔에서 데이타 저장까지는 확인이 되었습니다.


스파르타 즉문즉답





<!DOCTYPE html>
<html lang="en">
<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>

    <link href="https://fonts.googleapis.com/css2?family=Gowun+Batang:wght@400;700&display=swap" rel="stylesheet">

    <title>선착순 공동구매</title>

    <style>
        * {
            font-family: 'Gowun Batang', serif;
            color: white;
        }

        body {
            background-image: linear-gradient(0deg, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url('https://cdn.aitimes.com/news/photo/202010/132592_129694_3139.jpg');
            background-position: center;
            background-size: cover;
        }

        h1 {
            font-weight: bold;
        }

        .order {
            width: 500px;
            margin: 60px auto 0px auto;
            padding-bottom: 60px;
        }

        .mybtn {
            width: 100%;
        }

        .order > table {
            margin : 40px 0;
            font-size: 18px;
        }

        option {
            color: black;
        }
    </style>
    <script>
        $(document).ready(function () {
            show_order();
        });
        function show_order() {
            $.ajax({
                type: 'GET',
                url: '/mars',
                data: {},
                success: function (response) {
                    let rows = response['orders']
                    for (let i = 0; i < rows.length;i++){
                        let name = rows[i]['name']
                        let address = rows[i]['address']
                        let size = rows[i]['size']

                        let temp_html = '<tr>\n' +
                            '                <td>${name}</td>\n' +
                            '                <td>${address}</td>\n' +
                            '                <td>${size}</td>\n' +
                            '              </tr>'

                        $('#order-box').append(temp_html)
                    }

                }
            });
        }
        function save_order() {
            let name = $('#name').val()
            let address = $('#address').val()
            let size = $('#size').val()

            $.ajax({
                type: 'POST',
                url: '/mars',
                data: { name_give:name, address_give:address, size_give:size },
                success: function (response) {
                    alert(response['msg'])
                    window.location.reload()
                }
            });
        }
    </script>
</head>
<body>
    <div class="mask"></div>
    <div class="order">
        <h1>화성에 땅 사놓기!</h1>
        <h3>가격: 평 당 500원</h3>
        <p>
            화성에 땅을 사둘 수 있다고?<br/>
            앞으로 백년 간 오지 않을 기회. 화성에서 즐기는 노후!
        </p>
        <div class="order-info">
            <div class="input-group mb-3">
                <span class="input-group-text">이름</span>
                <input id="name" type="text" class="form-control">
            </div>
            <div class="input-group mb-3">
                <span class="input-group-text">주소</span>
                <input id="address" type="text" class="form-control">
            </div>
            <div class="input-group mb-3">
                <label class="input-group-text" for="size">평수</label>
                <select class="form-select" id="size">
                  <option selected>-- 주문 평수 --</option>
                  <option value="10평">10평</option>
                  <option value="20평">20평</option>
                  <option value="30평">30평</option>
                  <option value="40평">40평</option>
                  <option value="50평">50평</option>
                </select>
              </div>
              <button onclick="save_order()" type="button" class="btn btn-warning mybtn">주문하기</button>
        </div>
        <table class="table">
            <thead>
              <tr>
                <th scope="col">이름</th>
                <th scope="col">주소</th>
                <th scope="col">평수</th>
              </tr>
            </thead>
            <tbody id = "'order-box">
            </tbody>
          </table>
    </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.4zhcxku.mongodb.net/Cluster0?retryWrites=true&w=majority', tlsCAFile=ca)
db = client.dbsparta

@app.route('/')
def home():



   return render_template('index.html')

@app.route("/mars", methods=["POST"])
def web_mars_post():
    name_receive = request.form['name_give']
    address_receive = request.form['address_give']
    size_receive = request.form['size_give']
    doc = {
        'name':name_receive,
        'address':address_receive,
        'size':size_receive
    }
    db.mars.insert_one(doc)


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

@app.route("/mars", methods=["GET"])
def web_mars_get():
    order_list = list(db.mars.find({}, {'_id': False}))
    return jsonify({'orders':order_list})

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


보고 계신 화면 전체를 캡처해 주시면, 튜터님들이 빠르게 상황을 이해할 수 있어요.




작성한 코드 및 에러 메세지

C:\Users\user\Desktop\sparta\projects\mars\venv\Scripts\python.exe C:/Users/user/Desktop/sparta/projects/mars/app.py 

 * Serving Flask app 'app'

 * Debug mode: on

WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.

 * Running on all addresses (0.0.0.0)

 * Running on http://127.0.0.1:5000

 * Running on http://192.168.0.26:5000

Press CTRL+C to quit

 * Restarting with stat

 * Debugger is active!

 * Debugger PIN: 117-298-403

127.0.0.1 - - [06/Oct/2022 21:41:40] "GET / HTTP/1.1" 200 -

127.0.0.1 - - [06/Oct/2022 21:41:41] "GET /mars HTTP/1.1" 200 -

127.0.0.1 - - [06/Oct/2022 21:42:34] "POST /mars HTTP/1.1" 200 -

127.0.0.1 - - [06/Oct/2022 21:42:36] "GET / HTTP/1.1" 200 -

127.0.0.1 - - [06/Oct/2022 21:42:37] "GET /mars HTTP/1.1" 200 -

127.0.0.1 - - [06/Oct/2022 21:43:26] "GET / HTTP/1.1" 200 -

127.0.0.1 - - [06/Oct/2022 21:43:26] "GET /mars HTTP/1.1" 200 -

127.0.0.1 - - [06/Oct/2022 21:46:24] "GET / HTTP/1.1" 200 -

127.0.0.1 - - [06/Oct/2022 21:46:24] "GET /mars HTTP/1.1" 200 -

127.0.0.1 - - [06/Oct/2022 21:51:28] "GET / HTTP/1.1" 200 -

127.0.0.1 - - [06/Oct/2022 21:51:28] "GET /mars HTTP/1.1" 200 -

127.0.0.1 - - [06/Oct/2022 21:51:59] "GET / HTTP/1.1" 200 -

127.0.0.1 - - [06/Oct/2022 21:52:00] "GET /mars HTTP/1.1" 200 -

127.0.0.1 - - [06/Oct/2022 21:52:00] "POST /mars HTTP/1.1" 200 -

127.0.0.1 - - [06/Oct/2022 21:52:02] "GET / HTTP/1.1" 200 -

127.0.0.1 - - [06/Oct/2022 21:52:03] "GET /mars HTTP/1.1" 200 -

127.0.0.1 - - [06/Oct/2022 21:54:12] "GET / HTTP/1.1" 200 -

127.0.0.1 - - [06/Oct/2022 21:54:12] "GET /mars HTTP/1.1" 200 -




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