
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
맥북 사용중입니다.
이전 단계에서 Mongo DB 연결 시 맥북은 코드를 5줄 써야 작동이 되었는데, 4주차 넘어와서 다르게 응용하려니 오류 코드가 뜹니다.
작성한 코드 및 에러 메세지
from flask import Flask, render_template, request, jsonify
app = Flask(__name__)
from pymongo import MongoClient
import certifi
ca = certifi.where()
client = MongoClient('mongodb+srv://Sia:sparta@cluster0.6j5vg.mongodb.net/?retryWrites=true&w=majority',
tlsCAFile=ca)
db = client.dbsparta
@app.route('/')
def home():
return render_template('index.html')
@app.route("/mars", methods=["POST"])
def web_mars_post():
name_receive = request.form['name_give']
address_receive = request.form['address_give']
size_receive = request.form['size_give']
doc = {
'name':name_receive,
'address':address_receive,
'size':size_receive
}
db.mars.insert_one(doc)
return jsonify({'msg': 'Order complete!'})
@app.route("/mars", methods=["GET"])
def web_mars_get():
return jsonify({'msg': 'GET 연결 완료!'})
if __name__ == '__main__':
app.run('0.0.0.0', port=5000, debug=True)
/Users/silashin/Desktop/Coding/Projects/mars/venv/bin/python /Users/silashin/Desktop/Coding/Projects/mars/app.py
Traceback (most recent call last):
File "/Users/silashin/Desktop/Coding/Projects/mars/app.py", line 5, in <module>
db = client.dbsparta
NameError: name 'client' is not defined
종료 코드 1(으)로 완료된 프로세스
