Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
django templatedoesnotexist当前日期_Django - Fatal编程技术网

django templatedoesnotexist当前日期

django templatedoesnotexist当前日期,django,Django,我正在翻阅那本关于Django的书。我在第4章的中间。我无法呈现当前的_datetime.html模板视图。我做错了什么?模板加载程序似乎找不到正确的目录 Setting.py import os.path TEMPLATE_DIRS = ( os.path.join(os.path.dirname(__file__), 'templates').replace('\\','/'), # I've also tried: # '/Users/macuser/Python_Pro

我正在翻阅那本关于Django的书。我在第4章的中间。我无法呈现当前的_datetime.html模板视图。我做错了什么?模板加载程序似乎找不到正确的目录

Setting.py
import os.path

TEMPLATE_DIRS = (
    os.path.join(os.path.dirname(__file__), 'templates').replace('\\','/'),
    # I've also tried: # '/Users/macuser/Python_Projects/django_test1/templates',
)

views.py
from django.shortcuts import render_to_response
import datetime

def current_datetime(request):
    now = datetime.datetime.now()
    return render_to_response('current_datetime.html', {'current_date': now})

urls.py
from django.conf.urls import patterns, include, url
from django_test1.views import hello, my_homepage_view, current_datetime, hours_ahead


urlpatterns = patterns('',
    (r'^$', my_homepage_view),
    (r'^hello/$', hello),
    (r'^time/$', current_datetime),
    (r'^time/plus/(\d{1,2})/$', hours_ahead),)
我已经在我的项目文件夹中创建了我的模板目录,并在目录中创建了当前的_datetime.html

Setting.py
import os.path

TEMPLATE_DIRS = (
    os.path.join(os.path.dirname(__file__), 'templates').replace('\\','/'),
    # I've also tried: # '/Users/macuser/Python_Projects/django_test1/templates',
)

views.py
from django.shortcuts import render_to_response
import datetime

def current_datetime(request):
    now = datetime.datetime.now()
    return render_to_response('current_datetime.html', {'current_date': now})

urls.py
from django.conf.urls import patterns, include, url
from django_test1.views import hello, my_homepage_view, current_datetime, hours_ahead


urlpatterns = patterns('',
    (r'^$', my_homepage_view),
    (r'^hello/$', hello),
    (r'^time/$', current_datetime),
    (r'^time/plus/(\d{1,2})/$', hours_ahead),)
错误:

TemplateDoesNotExist at /time/
current_datetime.html
Request Method: GET
Request URL:
Django Version: 1.4
Exception Type: TemplateDoesNotExist
Exception Value:    
current_datetime.html
Exception Location: /Library/Python/2.7/site-packages/django/template/loader.py in find_template, line 138
Python Executable:  /usr/bin/python
Python Version: 2.7.1
Python Path:    
['/Users/macuser/Python_Projects/django_test1',
 '/Library/Python/2.7/site-packages/distribute-0.6.27-py2.7.egg',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC',
 '/Library/Python/2.7/site-packages']
Server time:    Mon, 23 Jul 2012 20:40:35 -0500
Template-loader postmortem

Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
Using loader django.template.loaders.app_directories.Loader:
/Library/Python/2.7/site-packages/django/contrib/auth/templates/current_datetime.html (File does not exist)

您尚未选中“渲染到”响应格式


仔细检查,您需要将context\u instance=RequestContext(request)添加到响应中这是一个愚蠢的错误。我没有创建实际的应用程序:python manage.py startapp“appName”。我将“assert False”放在设置文件中,意识到django甚至没有使用我的settings.py文件