본문 바로가기
Python/Flask Server

Flask에 CSS 파일 포함하기 <link rel="stylesheet" href="{{ url_for('static', filename='폴더명/파일명.css') }}">

by leehii 2022. 7. 16.

css 적용을 위해선 html파일을 랜더링한것 처럼 파일을 불러와야함

 

css파일은 static file이므로 이를 랜더링하려면

 

=========================================================================================

 

from flask import Flask, render_template

 

app = Flask(__name__)

 

@app.route("/")

 

def main():

return render_template('main.html')

 

 

if __name_ _ == " __main__ " :

    app.run ()

 

 

 

===============================================================================

 

 

<!doctype html>

<html>

<head>

<link rel="stylesheet" href="{{ url_for('static', filename='css폴더이름/파일이름.css') }}">

</head>

 

<body>

body안의 내용

</body>

 

</html>