TIL,WIL(일간,주간 회고)
2022. 12. 05 TIL 파이썬Flask get연결 문제
worldint
2022. 12. 6. 01:13
-문제점:
아래와 같은 flask코드가 있을때 클라이언트에서 get요청을 하면 아래의 @app.route가 실행되는줄알았다
@app.route("/tech")
def tech():
return render_template('tech.html')
@app.route("/tech", methods=["GET"])
def tech_get():
techList = list(db.tech.find({},{'_id':False}))
return jsonify({'techList':techList})
-알게된점:
app.route('/tech') 이렇게 메소드가 안써져있어도 디폴트가 GET방식인거같다
그렇게 판단한 이유는
@app.route('/tech')
def tech():
print(request.method)
return render_template('tech.html')
위 코드로 request.method를 출력해보면 GET으로 나온다
그러므로
@app.route('/tech') 와 @app.route('/tech', methods=['GET'])이것은 동시에 쓸수없다.