나의 개발일지(김지헌)
GET, POST 요청 하기 app.py 본문
app.py
from flask import Flask, render_template, request, jsonify
from pymongo import MongoClient
import certifi
ca = certifi.where()
client = MongoClient('mongodb+srv://youwa65:ss3108@cluster0.wrjvztk.mongodb.net/Cluster0?retryWrites=true&w=majority', tlsCAFile=ca)
db = client.youwa65
app = Flask(__name__)
@app.route('/')
def home():
return render_template('index.html')
@app.route("/homework", methods=["POST"])
def homework_post():
name_receive = request.form['name_give']
comment_receive = request.form['comment_give']
doc = {'name': name_receive,'comment':comment_receive}
db.music.insert_one(doc)
return jsonify({'msg': '저장완료!!'})
@app.route("/homework", methods=["GET"])
def homework_get():
comment = list(db.music.find({}, {'_id': False}))
return jsonify({'comments':comment})
if __name__ == '__main__':
app.run('0.0.0.0', port=5000, debug=True)
(변수)comment = list(db.몽고디비 폴더이름.find({},{'_id':False})) 아이디는 필요없음
return = jsonify({'변수 저장할 리스트 이름??':comment})
comment = list(db.music.find({}, {'_id': False}))
return jsonify({'comments':comment})
'코드 및 잡다' 카테고리의 다른 글
버튼 누를시 카운터 올려서 표시하기 (0) | 2022.09.05 |
---|---|
GET,POST 요청하기 html (0) | 2022.09.05 |
크롤링 (0) | 2022.09.04 |
화성땅 공동구매 (0) | 2022.09.04 |
4주차 2 flask 서버 만들기 기본 코드 (0) | 2022.09.04 |