Mongodb, Pymongo, Robo3T, Flask를 활용하여 서버 만들기 연습
from flask import Flask, render_template, jsonify, request
app = Flask(__name__)
from pymongo import MongoClient
client = MongoClient('localhost', 27017)
db = client.dbsparta
@app.route('/')
def home():
return render_template('index.html')
@app.route('/order', methods=['POST'])
def order():
name_receive = request.form['name_give']
select_receive = request.form['select_give']
phone_receive = request.form['phone_give']
address_receive = request.form['address_give']
time_receive = request.form['time_give']
doc = {
'time': time_receive,
'name': name_receive,
'select': select_receive,
'phone': phone_receive,
'address': address_receive
}
db.orders.insert_one(doc)
return jsonify({'message': '주문되었습니다.'})
@app.route('/order', methods=['GET'])
def listing():
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)
'Study' 카테고리의 다른 글
CSS / 글자 자동 줄바꿈 기준 변경 / word-break (0) | 2023.01.31 |
---|---|
웹 개발 3주차 숙제 (0) | 2021.09.05 |
웹 개발 2주차 숙제 (0) | 2021.08.30 |
웹 개발 1주차 숙제 (0) | 2021.08.16 |
MySQL workbench 처음 실행시 connections에 root가 없을 때 해결방법(Mac 사용자) (0) | 2021.03.28 |
댓글