2016-07-05 90 views
0

我一直在试图使用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'), 
] 

我views.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

回答

0

在第二个例子中,模板名称应该是一个字符串

return render(request, 'buisnesscard/form.html', {}) 

的实例教程可能会有所帮助:https://docs.djangoproject.com/en/1.9/intro/tutorial03/#a-shortcut-render

+0

纠正错误仍然给我相同的TemplateDoesNotExist错误帮助 –

+0

你是否正确指出了Django实际存在于buisnesscard/templates/buisnesscard/form.html中的文件? –

+0

模板文件夹应为小写 –