본문 바로가기
개발/Python3

django.template.exceptions.TemplateDoesNotExist 해결방법

by Devsong26 2021. 9. 2.

django로 웹 페이지를 만들고 있다.

TemplateDoesNotExist 에러가 발생했다.

 

어떻게 해결해야 할까?

 


 

BASE_DIR을 지정한다.

 

TEMPLATES[0]["DIRS"]에 template 디렉터리 경로를 입력한다.

 

BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'resources')],
        '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',
            ],
        },
    },
]

 

그리고 컨트롤러의 render 함수 파라미터로 html의 경로를 입력하면 해결된다.

 

from django.shortcuts import render

...
return render(request, HTML_PATH, {})
...