망한 것 같음.
네트워크 오류 자꾸 발생함.
보완 필요.
from flask import Flask, render_template, jsonify, request
app = Flask(__name__)
from pymongo import MongoClient
client = MongoClient('localhost', 27017)
db = client.dbsparta
## HTML 화면 보여주기
@app.route('/')
def homework():
return render_template('index.html')
@app.route('/order', methods=['POST'])
def write_order():
orderer_receive = request.form['orderer-give']
quantity_receive = request.form['quantity_give']
address_receive = request.form['address_give']
pnumber_receive = request.form['pnumber_give']
doc = {
'orderer':orderer_receive,
'quantity':quantity_receive,
'address':address_receive,
'pnumber': pnumber_receive
}
db.orders.insert_one(doc)
return jsonify({'msg': '주문완료!'})
# 주문 목록보기(Read) API
@app.route('/order', methods=['GET'])
def view_orders():
orders = list(db.orders.find({},{'_id':False}))
return jsonify({'all_orders': orders})
if __name__ == '__main__':
app.run('0.0.0.0', port=5000, debug=True)
'코딩' 카테고리의 다른 글
22.01.12 Git (0) | 2022.01.12 |
---|---|
스파르타 코딩클럽 5주차 완강 (0) | 2022.01.04 |
22.01.02 3주차 과제 (0) | 2022.01.02 |
22.01.02 2주차 과제 (0) | 2022.01.02 |
21.12.26 1주차 과제 (0) | 2021.12.26 |