엄청 과거 이야기/Flask

Flask.py #3 js,css 등 파일을 연결시키자 ( render_template )

반응형

이번 강의에서는 파이썬 파일은 건들지 않습니다.

/

 application.py

 templates/

index.html

이런식으로 구조가 짜져있지 않습니까?

그럼 루트 폴더에 새로운 디렉터리를 만들어 줍시다.

 

이름은 상관없어요! 하지만 static 이라는 이름을 추천합니다! ( 이유는 그냥 해외분들이 그렇게 쓰더라구요,,)

 

그럼 이런식으로 구조가 짜일껍니다.

/

 application.py

 static/

 templates/

index.html

이제 static 폴더안에 js 나 css 등의 파일이나 이것들이 담긴 폴더를 넣어줍시다.

/

 application.py

 static/

script.js

style.css

 templates/

index.html

이렇게 하셧으면 index.html 을 수정해 줍시다.

 

<!-- CSS --> <link href="{{ url_for('static', filename='style.css') }}" rel="stylesheet"> <!-- JS --> <script src="{{ url_for('static', filename='script.js') }}" > </script> 

 

이런식으로 해서 적용을 해주시면 스타일과 자바스크립트가 적용이 됩니다 짞짞짞