2012-07-24 2 views
0

장고 서적을 살펴 보겠습니다. 4 장 중간에 있습니다. current_datetime.html 템플릿 뷰를 렌더링 할 수 없습니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까? 템플릿 로더가 올바른 디렉토리를 찾지 못하는 것 같습니다. http://www.djangobook.com/en/2.0/chapter04/django templatedoesnotexist current_date

내 프로젝트 폴더에 내 템플릿 디렉토리를 만들고 디렉토리에 current_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),) 

오류 : https://docs.djangoproject.com/en/dev/topics/http/shortcuts/#render-to-response

그것을 통해 이동

당신이 선택 havn't는
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) 

답변

0

이것은 어리석은 실수였습니다. 나는 실제 app : python manage.py startapp "appName"을 만들지 않았다. 나는 "assert False"를 설정 파일에 넣었고 django가 나의 settings.py 파일조차 사용하지 않는다는 것을 깨달았다.

0

에는 render_to_response 형식, 당신은 추가 할 필요가 context_instance = RequestContext 응답에 (요청)

+0

그건 문제가 아니에요, 고마워요. – Benamir

관련 문제