我正在开始一个非常简单的Django应用程序但是在扩展html文件方面遇到了麻烦。
我base.html
内有index.html
和my_site/my_app/templates/my_app
。
即。
my_site/my_app/templates/my_app/base.html
和my_site/my_app/templates/my_app/index.html
。
在index.html
文件中我有{% extends 'base.html' %}
。
我的settings.py
文件有
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
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',
],
},
},
]
但是当我在http://127.0.0.1:8000/index/
访问我的索引视图时:
def index(request):
return render(request, 'my_app/index.html')
我收到以下错误:
TemplateDoesNotExist at /index/
base.html
Request Method: GET
Request URL: http://127.0.0.1:8000/index/
Django Version: 1.10.3
Exception Type: TemplateDoesNotExist
Exception Value: base.html
我是否将base.html
文件保存在错误的位置,还是其他内容?我无法解决这个问题。
答案 0 :(得分:1)
应该在my_site / my_app / templates或my_site / templates。