부트캠프TIL, WIL/AI웹개발(스파르타코딩클럽)
[AI웹개발][46일차TIL] Django에서 TemplateDoesNotExist이 뜰때
우지uz
2023. 5. 18. 15:59
views.py 에서 띄우고자 하는 html파일의 경로를 찾지 못할 때 뜨는 에러입니다.
settings.py 에 BASE_DIR이 설정 되어 있는데, 그걸 templates로(원하는폴더이름) 설정해두어야 한다.
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
django 에서 자체적으로 BASE_DIR에 대한 정의를 내려놓는데 그걸
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR/'templates/'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
templates 라는 폴더로 지정해두어야 한다.