-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
嘗試增加'APP_DIRS:TRUE'到您的模板字典([文件](https://開頭docs.djangoproject.com/en/1.10/ref/settings/#app-dirs)) – Sayse
@Sayse,我已經有了。我將編輯我的問題以包含它。 – Paradox
等待,你的錯誤說你正在使用Django 1.5.1?.. – Sayse