WEB
FLASK, MongoDB 와 서버 구축
with_AI
2022. 4. 12. 20:10
FLASK
- 서버를 만들 수 있는 라이브러리
- 프레임워크
플라스크 설치
pip install flask
app.py
flask 예제 코드
from flask import Flask
app = Flask(__name__)
@app.route('/')
def home():
return 'This is Home!'
if __name__ == '__main__':
app.run('0.0.0.0',port=5000,debug=True)
prac
- static
- templates
-- index.html
index.html 예제 코드
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<title>Document</title>
<script>
function hey(){
alert('안녕!')
}
</script>
</head>
<body>
<button onclick="hey()">나는 버튼!</button>
</body>
</html>
localhost:5000
- 우리가 만든 로컬 서버
- 로컬 환경에서 나만 볼 수 있음
- 디버깅 할때 쓰는것
본격 API 만들기
GET
- READ
POST
- CREATE
- DELETE
- UPDATE
프로젝트에 필요한 라이브러리
- flask
- pymongo
- dnspython