您好我是Django的新手,并尝试通过视频和文档学习,但卡住从模板返回html页面。
虽然posts / index.html存在,但得到错误“TemplateDoesNotExist at / posts /”
不知道我哪里错了,请指教。
这是我的目录结构
djangoproject / urls.py
from django.contrib import admin
from django.conf.urls import url, include
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^posts/', include('posts.urls')),
]
和Django应用程序称为“帖子”
文章/ urls.py
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index')
]
帖/视图
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
return render(request, 'posts/index.html')
文章/模板/帖/ index.html中
<h3>message from index.html</h3>
这是来自settings.py的
我的模板TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'posts/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',
],
},
},
]