flask controller(app.py)

Calvin Park·2022년 5월 31일
0

from flask import Flask, render_template, request, jsonify
from pymongo import MongoClient

client = MongoClient(
'mongodb+srv:yourMongoDburl')
db = client.dbsparta

app = Flask(name)

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

@app.route("/homework", methods=["POST"])
def homework_post():
nick_name_receive = request.form['nickName']
comment_receive = request.form['comment']
doc = {
'nick_name': nick_name_receive,
'comment': comment_receive
}
db.fanBlog.insert_one(doc)
return jsonify({'msg': '작성 완료!!'})

@app.route("/homework", methods=["GET"])
def homework_get():
blog_list = list(db.fanBlog.find({}, {'_id': False}))
print(blog_list)
return jsonify({'blog_list': blog_list})

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

profile
Personal Velog Note

0개의 댓글