## mysite/mysite/settings.py
## mysite是项目名
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')], # 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',
],
},
},
]
这个templates文件夹是放在project的目录下面的,是项目中或者说项目中所有的应用公用的一些模板
## mysite/mysite/settings.py
## mysite/app1/
## mysite是项目名字,app1是应用名字
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'app1/templates')], ## templates
'APP_DIRS': True,
'OPTIONS': {
'conte

本文详细介绍了Django项目中模板配置的两种情况:全局模板目录和应用专用模板目录。BASE_DIR指项目的绝对路径。全局'DIRS':[os.path.join(BASE_DIR,'templates')]设置用于存放公共模板,方便各应用调用;而应用如'app1'的专用模板只需在'app1/templates'下,无需额外配置,Django会自动查找。这样的配置提高了代码复用性和组织性。
最低0.47元/天 解锁文章
1237

被折叠的 条评论
为什么被折叠?



