![[파이썬 플라스크] jinja2.exceptions.TemplateNotFound에러 해결 방법 [파이썬 플라스크] jinja2.exceptions.TemplateNotFound에러 해결 방법](http://t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png)
이번 포스팅에서는 웹 플레임워크 플라스크에서 자주 발생 되는 오류인 jinja2.exceptions.TemplateNotFound 해결 방법에 대해 알아보겠습니다.
파이썬 예제
아래는 코드 예제입니다.
![[파이썬 플라스크] jinja2.exceptions.TemplateNotFound에러 해결 방법 - undefined - 모든 영역 예제 코드](http://t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png)
/html_test url로 접속하면 html페이지(login.html파일)을 띄우는 코드인데요.
실행을 해보면
브라우저 창에는 Internal Server Error가 발생하고,
![[파이썬 플라스크] jinja2.exceptions.TemplateNotFound에러 해결 방법 - undefined - 모든 영역 internal server error](http://t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png)
터미널에는 아래와 같이 jinja2.exceptions에러가 발생합니다.
![[파이썬 플라스크] jinja2.exceptions.TemplateNotFound에러 해결 방법 - undefined - 모든 영역 jinja2에러](http://t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png)
이는 플라스크가 login.html이 어딨는지 찾지 못하겠다 라고 말하는 것입니다.
혹시 여러분의 html파일은 어디에 있나요?
![[파이썬 플라스크] jinja2.exceptions.TemplateNotFound에러 해결 방법 - undefined - 모든 영역 [파이썬 플라스크] jinja2.exceptions.TemplateNotFound에러 해결 방법 - undefined - 모든 영역](http://t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png)
저의 경우 예제 코드에서 사용한 login.html파일의 위치는 실행 파일과 같은 레벨에 있습니다.
![[파이썬 플라스크] jinja2.exceptions.TemplateNotFound에러 해결 방법 - undefined - 모든 영역 [파이썬 플라스크] jinja2.exceptions.TemplateNotFound에러 해결 방법 - undefined - 모든 영역](http://t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png)
혹시 저와 비슷한 상황은 아니신가요?
정답 부터 말하자면,
파이썬 플라스크가 해당 html파일을 찾기 위해선 정해진 규칙을 따라줘야 합니다.
먼저 templates 폴더를 만들고 그 안에 사용할 html 페이지를 넣어줘야 한다는 것입니다.
![[파이썬 플라스크] jinja2.exceptions.TemplateNotFound에러 해결 방법 - undefined - 모든 영역 templates폴더안에 html넣기](http://t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png)
정리하자면, 해당 html페이지 위치가 templates/login.html이어야 플라스크가 정상적으로 해당 html을 읽어 올 수 있습니다.
여기서 자주 발생하는 실수로 폴더 이름을 templates가 아닌 template로 만드는 경우 입니다.
철자 하나만 틀려도 인식을 못하니 주의 하시기 바랍니다.
댓글