2017-01-24 217 views
-1

我以前见过这个问题,但我已经在使用较新的TEMPLATES数据结构,这是常见的解决方案。Django TemplateDoesNotExist at/rango/

从Django的书探戈,我目前在单元4.当我运行我的程序与python manage.py runserver

我收到以下错误:

TemplateDoesNotExist at /rango/ 

rango/index.html 

Request Method:  GET 
Request URL: http://127.0.0.1:8000/rango/ 
Django Version:  1.5.1 
Exception Type:  TemplateDoesNotExist 
Exception Value:  

rango/index.html 

下面是相关的代码我~/Workspace/wad2/tango_with_django_project/setings.py文件:

# Build paths inside the project like this: os.path.join(BASE_DIR, ...) 
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 
TEMPLATE_DIR = os.path.join(BASE_DIR, 'tango_with_django_project', 'templates') 
. 
. 
TEMPLATES = [ 
    { 
     'BACKEND': 'django.template.backends.django.DjangoTemplates', 
     'DIRS': [TEMPLATE_DIR], 
     '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', 
      ], 
     }, 
    }, 
] 
. 
. 

而且,这里是相关的代码在我~/Workspace/wad2/rango/views.py文件:

def index(request): 
    context_dict = {'boldmessage': "Crunchy, creamy, cookie, candy, cupcake!"} 

    return render(request, 'rango/index.html', context_dict) 

此外,我不能用直接路径解决这个问题,因为我试图用动态pahs来坚持教程。最后,我的模板位于~/Workspace/wad2/tango_with_django_project/templates/rango/index.html

+0

尝试增加'APP_DIRS:TRUE'到您的模板字典([文件](https://开头docs.djangoproject.com/en/1.10/ref/settings/#app-dirs)) – Sayse

+0

@Sayse,我已经有了。我将编辑我的问题以包含它。 – Paradox

+1

等待,你的错误说你正在使用Django 1.5.1?.. – Sayse

回答

0

这是解决通过更新我的Django的版本:

pip install django==1.10.5