반응형
템플릿 로딩 API
1. BACKEND : 템플릿 엔진 클래스
-내장 템플릿
- django templates : django.template.backends.django.DjangoTemplates
- jinja2 templates : django.template.backends.jinja2.Jinja2
2. DIRS : 템플릿 소스 디렉토리 리스트 ( 리스트 순서대로 검색한다. )
'DIRS' : [ os.path.join(BASE_DIR, 'templates') # 프로젝트 루트에 마스터 템플릿 폴더 ]
1)템플릿 폴더 명을 굳이 templates로 명명하지 않아도 된다.
2)윈도우의 경우 경로를 백슬래시 대신 슬래시를 사용한다.
'DIRS' : [ 'C:/Users/templates', ]
3. APP_DIRS : 응용 프로그램 내에서 템플릿을 찾아야 하는지의 여부
1) True일 경우 INSTALLED_APPS에서 "templates" 하위 디렉토리에서 템플릿을 찾기 때문에 DIRS가 비어 있는 경우에도
템플릿 엔진에서 응용 프로그램 템플릿을 찾을 수 있다.
2) APP_DIRS를 True로 하고 DIRS를 비워두는 것이 좋다.
4. OPTIONS : 백엔드 관련 설정
# settings.py TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [ os.path.join(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', ], }, }, ]
반응형
'Python > Django' 카테고리의 다른 글
[Python][Django] 모델 (0) | 2019.01.11 |
---|---|
[Python][Django] settings.py 의 Database API (0) | 2019.01.10 |
[Python][Django] Template Tag < For > (0) | 2019.01.07 |
[Python][Django] TypeError : ~ is not JSON serializable 해결 방법 (0) | 2019.01.03 |
RuntimeError: maximum recursion depth exceeded while calling a Python object (0) | 2018.03.18 |