【发布时间】:2016-11-07 15:30:08
【问题描述】:
我一直在尝试使用 django 创建一个简单的 Web 应用程序,但一直收到 TemplateDoesNotExist 错误
我的网址
from django.conf.urls import url, include
from django.contrib import admin
from buisnesscard import views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^login/', views.login, name='login'),
]
我的意见.py
from django.shortcuts import render
from django.template.loader import get_template
def login(request):
return render(request, get_template('form.html'), {})
我什至尝试过而不是使用 get_template
from django.shortcuts import render
def login(request):
return render(request, 'buisnesscard/templates/buisnesscard/form.html', {})
Settings.py
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',
],
},
},
]
尝试将目录更改为
'DIRS' :[ 'buisnesscard/templates/buisnesscard']
我的 html 文件包含一个简单的静态文件,它得到的错误为
form.html
Request Method: GET
Request URL: http://127.0.0.1:8000/login/
Django Version: 1.10b1
Exception Type: TemplateDoesNotExist
Exception Value:
form.html
Exception Location: C:\Python27\lib\site-packages\django-1.10b1-py2.7.egg\django\template\loader.py in get_template, line 25
Python Executable: C:\Python27\python.exe
Python Version: 2.7.9
Python Path:
['E:\\Django files\\forms',
'C:\\Python27\\lib\\site-packages\\django-1.10b1-py2.7.egg',
'C:\\Windows\\SYSTEM32\\python27.zip',
'C:\\Python27\\DLLs',
'C:\\Python27\\lib',
'C:\\Python27\\lib\\plat-win',
'C:\\Python27\\lib\\lib-tk',
'C:\\Python27',
'C:\\Python27\\lib\\site-packages']
Server time: Wed, 6 Jul 2016 10:57:11 +0530
目前在 python 版本 2.7 上运行
【问题讨论】:
标签: python-2.7 django-templates django-views