我使用linux
,python 3.4
,django 1.8.2
,pytmysql
Django的渲染模板不存在
在我的virtualenv有:
db.sqlite3
manage.py
new/
templates/
settings.py:
First我评论'DIRS':[],
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
#'DIRS': [],
'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',
],
},
},
]
然后加入这一部分:
TEMPLATE_DIRS = (
'/home/niloofar/django/niloofar/new/templates',
)
urls.py:
从new.views导入欢迎
urlpatterns = [
url(r'^welcome', welcome),
]
views.py:
from django.shortcuts import render
def welcome(request):
message = "welcome again:D"
return render(request, 'base.html', {'message': message})
在模板目录中,有base.html文件文件:
<html>
<body>
<p>* {{ message }} *</p>
</body>
</html>
当我刷新页面,它打印错误:
Exception Type: TemplateDoesNotExist
Exception Value: base.html
什么是你的'base.html'的完整路径? –
/home/niloofar/django/niloofar/new/templates/base.html – niloofar
试试$ ls -a/home/niloofar/django/niloofar/new/templates。你得到了什么? –