3omh4n
3omh4
3omh4n
  • 분류 전체보기 (65)
    • wargame - system (0)
      • DreamHack (9)
      • FTZ (5)
      • LoB (4)
      • pwnable.kr (1)
    • wargame - reversing (0)
      • DreamHack (5)
    • wargame - web (6)
      • webhacking.kr (3)
      • DreamHack (3)
      • HackCTF (0)
    • CS (21)
      • system (19)
      • reversing (0)
      • Linux (2)
    • python (5)
      • Flask (5)
    • C++ (3)
    • 개인기록 (2)
    • 이거저거 (4)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

최근 댓글

최근 글

태그

  • ROP
  • hacking
  • LOB
  • systemhacking
  • System
  • flask
  • error
  • Dreamhack
  • Programming
  • C++
  • ftz
  • BOF
  • RELRO
  • Devtools
  • Reversing
  • webhacking
  • hackerschool
  • python
  • langage
  • pwntools

티스토리

전체 방문자
오늘
어제
3omh4n
python/Flask

[python][flask]플라스크 기초-템플릿(render_template)

[python][flask]플라스크 기초-템플릿(render_template)
python/Flask

[python][flask]플라스크 기초-템플릿(render_template)

2022. 2. 14. 16:09

render_template

render_template은 flask에서 제공하는 함수로 지정한 폴더에 존재하는 html파일을 읽어오는 함수이다.

 

예제

다음과 같은 구성으로 정적파일(css, js, image,..)과 템플릿(html)들을 각각 static폴더와 templates 폴더에 저장하였다. flask객체는 폴더 지정을 통해 정적 파일과 템플릿의 위치를 추적한다.

 

 

 

 

 

app = Flask(__name__, static_folder='static', template_folder='templates')

 

static_folder를 지정하면 /static URL로 접근 가능하다. template_folder를 지정해주면 render_template() 함수를 통해 해당 템플릿 파일을 찾을 수 있다.

ex.py

from flask import Flask, render_template
app = Flask(__name__, static_folder='static', template_folder='templates')
@app.route('/hello')
def hello():
return render_template('hello.html')

 

hello.html

<html>
<head>
<title>hello</title>
</head>
<body>
<img src="/static/image/hello.png">
</body>
</html>

 

결과

https://github.com/gkdms1457/langage-review/tree/master/python/flask/templates

 

GitHub - gkdms1457/langage-review: review and practice programing langage

review and practice programing langage. Contribute to gkdms1457/langage-review development by creating an account on GitHub.

github.com

 

'python > Flask' 카테고리의 다른 글

[python][flask]플라스크 기초-redirect & errorhandler  (0) 2022.02.14
[python][flask]플라스크 기초-jinja2  (0) 2022.02.14
[python][flask]플라스크 기초-메서드(method)  (0) 2022.02.14
[python][flask]플라스크 기초-라우팅  (0) 2022.02.08
  • render_template
  • 예제
'python/Flask' 카테고리의 다른 글
  • [python][flask]플라스크 기초-redirect & errorhandler
  • [python][flask]플라스크 기초-jinja2
  • [python][flask]플라스크 기초-메서드(method)
  • [python][flask]플라스크 기초-라우팅
3omh4n
3omh4n

티스토리툴바

단축키

내 블로그

내 블로그 - 관리자 홈 전환
Q
Q
새 글 쓰기
W
W

블로그 게시글

글 수정 (권한 있는 경우)
E
E
댓글 영역으로 이동
C
C

모든 영역

이 페이지의 URL 복사
S
S
맨 위로 이동
T
T
티스토리 홈 이동
H
H
단축키 안내
Shift + /
⇧ + /

* 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.