공부 및 일상기록

<Flask> 시작하기 본문

개발

<Flask> 시작하기

낚시하고싶어요 2022. 9. 13. 14:43

Flask를 사용 하려면 사용하는 폴더 하위에 templates 와 static 이라는 두개의 폴더를 만들어야 한다.

사용할 폴더 하위에 templates, static 두개폴더 생성

app.py에는 기본적으로 사용하는 코드를 입력한다.

from flask import Flask, render_template
app = Flask(__name__)

@app.route('/')
def home():
   return render_template('index.html')

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

render_template는 templates 폴더에 만들어진 html을 불러오는 기능이다.

따라서 사용할 html파일은 templates폴더에 생성해야 하고 위처럼 render_template 이라는 명령어로 위처럼 불러온다.

(index.html은 내가 사용하고 싶은 html 파일 이다.)

'개발' 카테고리의 다른 글

브라우저 렌더링 과정  (0) 2023.01.13
<jQuery> 임포트 주소  (0) 2022.09.13
[jQuery+Ajax] 랜덤 이미지 바꾸기  (0) 2022.09.08
[jQuery] Ajax 연습 (GET)  (0) 2022.09.06
[jQuery] temp_html  (0) 2022.09.06