편집 기록

편집 기록
  • 프로필 nowp님의 편집
    날짜2020.04.27

    파이썬 flask 작은 쇼핑몰, 페이지변경이 안 됨.


    작은 쇼핑몰을 만들려고 노력하는 파이썬 초보입니다. 구조는 메인페이지->상세페이지->결제창 입니다.

    메인페이지에서 상품1, 상품2, 상품3, 상품4를 누르면 상세페이지에서 상품코드/가격/배송방법을 db에서 가져와서 뿌리는 형식으로 만들고 있습니다.

    이렇게 코드를 짰는데, 메인페이지에서 상품1을 누르던, 상품2를 누르던, 상품3을 누르던 상품 1 페이지만 계속 나오더군요. 다만 콘솔창에서 보면 데이터는 받아오는거 같은데 왜 이럴까요.

    $(document).ready(function () {
        console.log(123123)
        product = window.location.href
        product_link = product.split('=')
        console.log(product.split('='))
        console.log(window.location.href)
        detail_page(product_link[1])
    })
    
    function detail_page(product_id) {
        console.log(123)
        $.ajax({
            type: "GET",
            url: "/detail?product=" + product_id,
            data: {},
            success: function (response) {
                console.log(response);
                let product_info = response['product_info'];
                make_card(product_info['price'], product_info['code'], product_info['supply'], product_info['delivery'], product_info['tprice'])
    
            }
        })
    }
    
    function make_card(price, code, supply, coupon, delivery, tprice) {
        let temp_html = ' <tbody>\
                <tr>\
                    <th>판매가</th>\
                    <td class="price">' + price + '</td>\
                </tr>\
                <tr>\
                    <th>상품코드</th>\
                    <td class="code">'+ code + '</td>\
                </tr>\
                <tr>\
                    <th>제조사/공급사</th>\
                    <td>' + supply + '</td>\
                </tr>\
                <tr>\
                    <th>구매수량</th>\
                    <td>\
                        <div class="length">\
                            <input id="count" type="number" min="1" value="1">\
                                <a href="#a">증가</a>\
                                <a href="#a">감소</a>\
                    </div>\
                </td>\
            </tr>\
                    <tr>\
                        <th>사용가능쿠폰</th>\
                        <td>' + coupon + '</td>\
                    </tr>\
                    <tr>\
                        <th>옵션선택</th>\
                        <td>\
                            <select id="size">\
                                <option selected value>사이즈를 선택하세요(+0)</option>\
                                <option value="1">85</option>\
                                <option value="2">90</option>\
                                <option value="3">95</option>\
                                <option value="4">100</option>\
                                <option value="5">105</option>\
                                <option value="6">110</option>\
                                <option value="7">115</option>\
                                <option value="8">120</option>\
                                <option value="9">125</option>\
                            </select>\
                        </td>\
                    </tr>\
                    <tr>\
                        <th>배송비</th>\
                        <td>' + delivery + '</td>\
                    </tr>\
                    <tr>\
                        <th>결제금액</th>\
                        <td class="tprice"><b>'+ tprice + '</b>원</td>\
                    </tr>\
        </tbody>\
    </table>'
    }
    
    <body>
    
        <div class="product_view">
            <h2>SK대리점 하계 유니폼 상의</h2>
            <table>
                <caption>
                    <details class="hide">
                        <summary>상품정보</summary>
                        판매가, 상품코드, 옵션 및 결제금액 안내
                    </details>
                </caption>
                <colgroup>
                    <col style="width:173px;">
                    <col>
                </colgroup>
                <tbody>
                    <tr>
                        <th>판매가</th>
                        <td class="price">45,900</td>
                    </tr>
                    <tr>
                        <th>상품코드</th>
                        <td class="code">C004843</td>
                    </tr>
                    <tr>
                        <th>제조사/공급사</th>
                        <td class="supply">코오롱 / SK행복나래</td>
                    </tr>
                    <tr>
                        <th>구매수량</th>
                        <td>
                            <div class="length">
                                <input id="count" type="number" min="1" value="1">
                                <a href="#a">증가</a>
                                <a href="#a">감소</a>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <th>사용가능쿠폰</th>
                        <td class="coupon">0개</td>
                    </tr>
                    <tr>
                        <th>옵션선택</th>
                        <td>
                            <select id="size">
                                <option selected value>사이즈를 선택하세요(+0)</option>
                                <option value="1">85</option>
                                <option value="2">90</option>
                                <option value="3">95</option>
                                <option value="4">100</option>
                                <option value="5">105</option>
                                <option value="6">110</option>
                                <option value="7">115</option>
                                <option value="8">120</option>
                                <option value="9">125</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <th>배송비</th>
                        <td class="delivery">무료배송</td>
                    </tr>
                    <tr>
                        <th>결제금액</th>
                        <td class="tprice"><b>45,900</b>원</td>
                    </tr>
                </tbody>
            </table>
            <div class="img">
                <img src="{{url_for('static', filename='image/유니폼 1.jfif')}}" alt="">
                <ul>
                    <li class="on"><a href="#a"><img src="{{url_for('static', filename='image/유니폼 1.jfif')}}" alt=""></a>
                    </li>
                    <li><a href="#a"><img src="{{url_for('static', filename='image/유니폼2.jpg')}}" alt=""></a></li>
                </ul>
            </div>
            <div class="btns">
                <a href="#a" class="btn1">장바구니</a>
                <a href="#a" class="btn2">구매하기</a>
            </div>
        </div>
    
    </body>
    
    </html>
    
    서버
    @app.route('/')
    def home():
        return render_template('main.html')
    
    @app.route('/product_detail', methods=['GET'])
    def change_page():
        product_id = request.args.get('product')
        return render_template("22page.html", product_id=product_id)
    
    @app.route('/detail', methods=['GET'])
    def get_detail_product():
        product_id = request.args.get('product')
        print(product_id)
        product_info = db.project.find_one({'name':product_id},{'_id':0})
        print(product_info)
    
        return jsonify({'result': 'success', 'msg': '상세페이지에 접근하였습니다..', 'product_info':product_info})
    
    if __name__ == '__main__':
        app.run('127.0.0.1', port=5000, debug=True)
    
  • 프로필 알 수 없는 사용자님의 편집
    날짜2020.04.27

    파이썬 코드 질문


    작은 쇼핑몰을 만들려고 노력하는 파이썬 초보입니다. 구조는 메인페이지->상세페이지->결제창 입니다.

    메인페이지에서 상품1, 상품2, 상품3, 상품4를 누르면 상세페이지에서 상품코드/가격/배송방법을 db에서 가져와서 뿌리는 형식으로 만들고 있습니다.

    이렇게 코드를 짰는데, 메인페이지에서 상품1을 누르던, 상품2를 누르던, 상품3을 누르던 상품 1 페이지만 계속 나오더군요. 다만 콘솔창에서 보면 데이터는 받아오는거 같은데 왜 이럴까요…

    $(document).ready(function () {
        console.log(123123)
        product = window.location.href
        product_link = product.split('=')
        console.log(product.split('='))
        console.log(window.location.href)
        detail_page(product_link[1])
    })
    
    function detail_page(product_id) {
        console.log(123)
        $.ajax({
            type: "GET",
            url: "/detail?product=" + product_id,
            data: {},
            success: function (response) {
                console.log(response);
                let product_info = response['product_info'];
                make_card(product_info['price'], product_info['code'], product_info['supply'], product_info['delivery'], product_info['tprice'])
    
            }
        })
    }
    
    function make_card(price, code, supply, coupon, delivery, tprice) {
        let temp_html = ' <tbody>\
                <tr>\
                    <th>판매가</th>\
                    <td class="price">' + price + '</td>\
                </tr>\
                <tr>\
                    <th>상품코드</th>\
                    <td class="code">'+ code + '</td>\
                </tr>\
                <tr>\
                    <th>제조사/공급사</th>\
                    <td>' + supply + '</td>\
                </tr>\
                <tr>\
                    <th>구매수량</th>\
                    <td>\
                        <div class="length">\
                            <input id="count" type="number" min="1" value="1">\
                                <a href="#a">증가</a>\
                                <a href="#a">감소</a>\
                    </div>\
                </td>\
            </tr>\
                    <tr>\
                        <th>사용가능쿠폰</th>\
                        <td>' + coupon + '</td>\
                    </tr>\
                    <tr>\
                        <th>옵션선택</th>\
                        <td>\
                            <select id="size">\
                                <option selected value>사이즈를 선택하세요(+0)</option>\
                                <option value="1">85</option>\
                                <option value="2">90</option>\
                                <option value="3">95</option>\
                                <option value="4">100</option>\
                                <option value="5">105</option>\
                                <option value="6">110</option>\
                                <option value="7">115</option>\
                                <option value="8">120</option>\
                                <option value="9">125</option>\
                            </select>\
                        </td>\
                    </tr>\
                    <tr>\
                        <th>배송비</th>\
                        <td>' + delivery + '</td>\
                    </tr>\
                    <tr>\
                        <th>결제금액</th>\
                        <td class="tprice"><b>'+ tprice + '</b>원</td>\
                    </tr>\
        </tbody>\
    </table>'
    }
    
    <body>
    
        <div class="product_view">
            <h2>SK대리점 하계 유니폼 상의</h2>
            <table>
                <caption>
                    <details class="hide">
                        <summary>상품정보</summary>
                        판매가, 상품코드, 옵션 및 결제금액 안내
                    </details>
                </caption>
                <colgroup>
                    <col style="width:173px;">
                    <col>
                </colgroup>
                <tbody>
                    <tr>
                        <th>판매가</th>
                        <td class="price">45,900</td>
                    </tr>
                    <tr>
                        <th>상품코드</th>
                        <td class="code">C004843</td>
                    </tr>
                    <tr>
                        <th>제조사/공급사</th>
                        <td class="supply">코오롱 / SK행복나래</td>
                    </tr>
                    <tr>
                        <th>구매수량</th>
                        <td>
                            <div class="length">
                                <input id="count" type="number" min="1" value="1">
                                <a href="#a">증가</a>
                                <a href="#a">감소</a>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <th>사용가능쿠폰</th>
                        <td class="coupon">0개</td>
                    </tr>
                    <tr>
                        <th>옵션선택</th>
                        <td>
                            <select id="size">
                                <option selected value>사이즈를 선택하세요(+0)</option>
                                <option value="1">85</option>
                                <option value="2">90</option>
                                <option value="3">95</option>
                                <option value="4">100</option>
                                <option value="5">105</option>
                                <option value="6">110</option>
                                <option value="7">115</option>
                                <option value="8">120</option>
                                <option value="9">125</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <th>배송비</th>
                        <td class="delivery">무료배송</td>
                    </tr>
                    <tr>
                        <th>결제금액</th>
                        <td class="tprice"><b>45,900</b>원</td>
                    </tr>
                </tbody>
            </table>
            <div class="img">
                <img src="{{url_for('static', filename='image/유니폼 1.jfif')}}" alt="">
                <ul>
                    <li class="on"><a href="#a"><img src="{{url_for('static', filename='image/유니폼 1.jfif')}}" alt=""></a>
                    </li>
                    <li><a href="#a"><img src="{{url_for('static', filename='image/유니폼2.jpg')}}" alt=""></a></li>
                </ul>
            </div>
            <div class="btns">
                <a href="#a" class="btn1">장바구니</a>
                <a href="#a" class="btn2">구매하기</a>
            </div>
        </div>
    
    </body>
    
    </html>
    
    서버
    @app.route('/')
    def home():
        return render_template('main.html')
    
    @app.route('/product_detail', methods=['GET'])
    def change_page():
        product_id = request.args.get('product')
        return render_template("22page.html", product_id=product_id)
    
    @app.route('/detail', methods=['GET'])
    def get_detail_product():
        product_id = request.args.get('product')
        print(product_id)
        product_info = db.project.find_one({'name':product_id},{'_id':0})
        print(product_info)
    
        return jsonify({'result': 'success', 'msg': '상세페이지에 접근하였습니다..', 'product_info':product_info})
    
    if __name__ == '__main__':
        app.run('127.0.0.1', port=5000, debug=True)
    
  • 프로필 편집요청빌런님의 편집
    날짜2020.04.27

    파이썬 코드 질문


    작은 쇼핑몰을 만들려고 노력하는 파이썬 초보입니다. 구조는 메인페이지->상세페이지->결제창 입니다.

    메인페이지에서 상품1, 상품2, 상품3, 상품4를 누르면 상세페이지에서 상품코드/가격/배송방법을 db에서 가져와서 뿌리는 형식으로 만들고 있습니다.

    이렇게 코드를 짰는데, 메인페이지에서 상품1을 누르던, 상품2를 누르던, 상품3을 누르던 상품 1 페이지만 계속 나오더군요. 다만 콘솔창에서 보면 데이터는 받아오는거 같은데 왜 이럴까요…

    $(document).ready(function () {
        console.log(123123)
        product = window.location.href
        product_link = product.split('=')
        console.log(product.split('='))
        console.log(window.location.href)
        detail_page(product_link[1])
    })
    
    function detail_page(product_id) {
        console.log(123)
        $.ajax({
            type: "GET",
            url: "/detail?product=" + product_id,
            data: {},
            success: function (response) {
                console.log(response);
                let product_info = response['product_info'];
                make_card(product_info['price'], product_info['code'], product_info['supply'], product_info['delivery'], product_info['tprice'])
    
            }
        })
    }
    
    function make_card(price, code, supply, coupon, delivery, tprice) {
        let temp_html = ' <tbody>\
                <tr>\
                    <th>판매가</th>\
                    <td class="price">' + price + '</td>\
                </tr>\
                <tr>\
                    <th>상품코드</th>\
                    <td class="code">'+ code + '</td>\
                </tr>\
                <tr>\
                    <th>제조사/공급사</th>\
                    <td>' + supply + '</td>\
                </tr>\
                <tr>\
                    <th>구매수량</th>\
                    <td>\
                        <div class="length">\
                            <input id="count" type="number" min="1" value="1">\
                                <a href="#a">증가</a>\
                                <a href="#a">감소</a>\
                    </div>\
                </td>\
            </tr>\
                    <tr>\
                        <th>사용가능쿠폰</th>\
                        <td>' + coupon + '</td>\
                    </tr>\
                    <tr>\
                        <th>옵션선택</th>\
                        <td>\
                            <select id="size">\
                                <option selected value>사이즈를 선택하세요(+0)</option>\
                                <option value="1">85</option>\
                                <option value="2">90</option>\
                                <option value="3">95</option>\
                                <option value="4">100</option>\
                                <option value="5">105</option>\
                                <option value="6">110</option>\
                                <option value="7">115</option>\
                                <option value="8">120</option>\
                                <option value="9">125</option>\
                            </select>\
                        </td>\
                    </tr>\
                    <tr>\
                        <th>배송비</th>\
                        <td>' + delivery + '</td>\
                    </tr>\
                    <tr>\
                        <th>결제금액</th>\
                        <td class="tprice"><b>'+ tprice + '</b>원</td>\
                    </tr>\
        </tbody>\
    </table>'
    }
    
    서버
    @app.route('/')
    def home():
        return render_template('main.html')
    
    @app.route('/product_detail', methods=['GET'])
    def change_page():
        product_id = request.args.get('product')
        return render_template("22page.html", product_id=product_id)
    
    @app.route('/detail', methods=['GET'])
    def get_detail_product():
        product_id = request.args.get('product')
        print(product_id)
        product_info = db.project.find_one({'name':product_id},{'_id':0})
        print(product_info)
    
        return jsonify({'result': 'success', 'msg': '상세페이지에 접근하였습니다..', 'product_info':product_info})
    
    if __name__ == '__main__':
        app.run('127.0.0.1', port=5000, debug=True)
    
  • 프로필 알 수 없는 사용자님의 편집
    날짜2020.04.27

    파이썬 코드 질문


    작은 쇼핑몰을 만들려고 노력하는 파이썬 초보입니다. 구조는 메인페이지->상세페이지->결제창 입니다.

    메인페이지에서 상품1, 상품2, 상품3, 상품4를 누르면 상세페이지에서 상품코드/가격/배송방법을 db에서 가져와서 뿌리는 형식으로 만들고 있습니다.

    이렇게 코드를 짰는데, 메인페이지에서 상품1을 누르던, 상품2를 누르던, 상품3을 누르던 상품 1 페이지만 계속 나오더군요. 다만 콘솔창에서 보면 데이터는 받아오는거 같은데 왜 이럴까요…

    <script type="text/javascript">
        $(document).ready(function () {
            console.log(123123)
            product = window.location.href
            product_link = product.split('=')
            console.log(product.split('='))
            console.log(window.location.href)
            detail_page(product_link[1])
        })
    
        function detail_page(product_id) {
            console.log(123)
            $.ajax({
                type: "GET",
                url: "/detail?product=" + product_id,
                data: {},
                success: function (response) {
                    console.log(response);
                    let product_info = response['product_info'];
                    make_card(product_info['price'], product_info['code'], product_info['supply'], product_info['delivery'], product_info['tprice'])
    
                }
            })
        }
    
        function make_card(price, code, supply, coupon, delivery, tprice) {
            let temp_html = ' <tbody>\
                    <tr>\
                        <th>판매가</th>\
                        <td class="price">' + price + '</td>\
                    </tr>\
                    <tr>\
                        <th>상품코드</th>\
                        <td class="code">'+ code + '</td>\
                    </tr>\
                    <tr>\
                        <th>제조사/공급사</th>\
                        <td>' + supply + '</td>\
                    </tr>\
                    <tr>\
                        <th>구매수량</th>\
                        <td>\
                            <div class="length">\
                                <input id="count" type="number" min="1" value="1">\
                                    <a href="#a">증가</a>\
                                    <a href="#a">감소</a>\
                        </div>\
                    </td>\
                </tr>\
                        <tr>\
                            <th>사용가능쿠폰</th>\
                            <td>' + coupon + '</td>\
                        </tr>\
                        <tr>\
                            <th>옵션선택</th>\
                            <td>\
                                <select id="size">\
                                    <option selected value>사이즈를 선택하세요(+0)</option>\
                                    <option value="1">85</option>\
                                    <option value="2">90</option>\
                                    <option value="3">95</option>\
                                    <option value="4">100</option>\
                                    <option value="5">105</option>\
                                    <option value="6">110</option>\
                                    <option value="7">115</option>\
                                    <option value="8">120</option>\
                                    <option value="9">125</option>\
                                </select>\
                            </td>\
                        </tr>\
                        <tr>\
                            <th>배송비</th>\
                            <td>' + delivery + '</td>\
                        </tr>\
                        <tr>\
                            <th>결제금액</th>\
                            <td class="tprice"><b>'+ tprice + '</b>원</td>\
                        </tr>\
            </tbody>\
        </table>'
        }
    
    </script>
    

    -----------------서버

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

    @app.route('/product_detail', methods=['GET']) def change_page(): product_id = request.args.get('product') return render_template("22page.html", product_id=product_id)

    @app.route('/detail', methods=['GET']) def get_detail_product(): product_id = request.args.get('product') print(product_id) product_info = db.project.find_one({'name':product_id},{'_id':0}) print(product_info)

    return jsonify({'result': 'success', 'msg': '상세페이지에 접근하였습니다..', 'product_info':product_info})
    

    if name == 'main': app.run('127.0.0.1', port=5000, debug=True)