[Python] settings.py에서 Templates DIR 상대경로로 설정하기

[Python] settings.py에서 Templates DIR 상대경로로 설정하기

# settings.py import os BASE_DIR = Path(__file__).resolve().parent.parent TEMPLATES_DIR = os.path.join(BASE_DIR, "templates") TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [TEMPLATES_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', ], }, }, ]

# views.py from django.shortcuts import render def index(request): return render(request, 'myApp/index.html', context=my_dict) # index.html 경로 = tempaltes/myApp/index.html

from http://insubkim.tistory.com/102 by ccl(A) rewrite - 2021-11-20 19:00:49