300x250
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.orders.insert_one(doc)
return jsonify({'result': 'success', 'msg': '주문 완료!'})
# 주문 목록보기(Read) API
@app.route('/order', methods=['GET'])
def view_orders():
orders = list(db.orders.find({}, {'_id': False}))
return jsonify({'result': 'success', 'orders': orders})
if __name__ == '__main__':
app.run('0.0.0.0', port=5000, debug=True)
반응형
'AI 관련 > 개발일지' 카테고리의 다른 글
파이썬의 기초 (python 3.7) - 문자열 (2) | 2021.10.11 |
---|---|
파이썬의 기초 (python 3.7) (0) | 2021.10.10 |
3주차 스파르타 코팅클럽 왕초보 웹개발일지 (0) | 2021.08.15 |
2주차 스파르타 코팅클럽 왕초보 웹개발일지 (2) | 2021.08.10 |
1주차 스파르타 코딩클럽 왕초보 웹개발 일지 (2) | 2021.08.09 |
댓글