当我在settings.py 中运行以下代码时
TEMPLATES = [{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join('BASE_DIR','template')],
'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',
],
},
}, ]
它显示error template not found
,但当我在settings.py 中执行以下代码时
TEMPLATES = [{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['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',
],
},
}, ]
这很好用!
os.path.join('BASE_DIR','template')
实际上是什么意思?
您可以尝试以下步骤:。
-
在settings.py文件的顶部标题部分声明'import-os'命令。
-
在定义DIRS':[os.path.join(BASE_DIR,'template'(]时,从自动建议中获取操作系统,而不是键入。
TEMPLATES = [
{
'BACKEND': `enter code here`'django.template.backends.django.DjangoTemplates',
'DIRS': ['templates'],
'APP_DIRS': True,
我认为有效
os.path.join(DIR(正在使用旧版本的DJANGO