在settings.py中,项目默认的模板配置如下。
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'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’,
……
各个选项含义如下。
BACKEND:设置处理模板的模板引擎。
DIRS:配置模板的搜索路径。在项目中使用自定义的模板时,需要在此配置模板的搜索路径。例如,'DIRS': [os.path.join(BASE_DIR,'hello/templates')]。
APP_DIRS:默认值为True,表示Django默认在项目应用的templates路径中搜索模板。
OPTIONS:设置可选项。其中的context_processors用于设置模板使用的上下文处理器。