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

 

 

 

 

'WEB' 카테고리의 다른 글

WEB 서비스 배포  (0) 2022.04.12
Python & 크롤링, DB  (0) 2022.04.12
jQuery와 Ajax  (0) 2022.04.12
JS 기본 문법  (0) 2022.04.12
HTML 실습  (0) 2022.04.11