본문 바로가기

끄적끄적

4주차 부족한부분 공부

4주차 서버만들기

flask: 서버를 구동시켜주는 패키지 => 프레임워크같은거

flask시작코드
from flask import Flask
app = Flask(__name__)

@app.route('/')             => localhost:5000
def home():
   return 'This is Home!'


@app.route('/mypage')         => localhost:5000/mypage     
def mypage():
   return 'This is my page'

if __name__ == '__main__':  
   app.run('0.0.0.0',port=5000,debug=True)

=> 이렇게만 적고 '실행'해보면 서버가 실행된다. localhost:5000실행하면 글이 나옴

      그리고 거기에 /mypage실행하면  'This is my page' 라고 뜸

 


flask코드 이해하기

 

 

저기 return에 입력하면 브라우저에서 저 글을 확인할 수 있는데 그렇타고 해서 저 안에 모든 html을 적을 순 없으니 templates파일안에 index.html을 만들어서 app.py와 연결을 해준다.

 

(약간 html에 css랑 javascript를 link로 연결하는 것 처럼)

 

 

👇👇👇

template(s빼고)를 render하고 return에 똑같이 적어주고 index.html을 연결한다.

 

get (클라이언트,서버)
POST(클라이언트,서버)

 

'끄적끄적' 카테고리의 다른 글

React memoization  (0) 2023.04.23
typescript interface  (0) 2023.04.12
좋은 TIL은 뭘까?(38)  (1) 2022.12.22
CSS-flex  (0) 2022.11.16
3주차 부족부분 공부  (0) 2022.10.28