【发布时间】:2018-12-11 04:08:01
【问题描述】:
我想知道 django 在哪里搜索 index.html
设置.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',
],
},
},
]
views.py
def index(request):
return render(request, 'index.html', {})
【问题讨论】:
-
我觉得这个问题太笼统了,不清楚。您的
'DIRS': ['templates'],不正确,请查看此 SO 问题中的所有 answers 以正确配置。请注意,默认情况下,Django 会在DIRS': ['/path/']中指定的路径中检索您的所有应用模板 -
我有模板文件夹和 index.html 文件...它在本地工作而不是在 pythonanywhere....
-
您需要在
DIRS中指定绝对路径,将您的path加入Django 的BASE_DIR,如下所示:'DIRS': [os.path.join(BASE_DIR, 'templates'),], -
它工作......但我无法验证你的答案
标签: python django django-templates django-views pythonanywhere