2011-08-11 92 views
1

我正在瀏覽一些關於學習Django的教程以瞭解即將發佈的項目,而且我無法正確加載模板。調試模式返回「ValueError」說它「需要多個值才能解包」。我正在運行Django的捆綁服務器。任何想法是什麼問題?任何幫助表示讚賞。Django查看ValueError render_to_response

這裏的痕跡:

Traceback: 
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response 
    111. response = callback(request, *callback_args, **callback_kwargs) 

File "/Users/tinwaijosephlee/Sites/djcode/dev2/../dev2/views.py" in hours_ahead 
    26. return render_to_response('plus.html', {'offset': offset, 'dt': dt}) 

File "/Library/Python/2.7/site-packages/django/shortcuts/__init__.py" in render_to_response 
    20. return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs) 

File "/Library/Python/2.7/site-packages/django/template/loader.py" in render_to_string 
    181. t = get_template(template_name) 

File "/Library/Python/2.7/site-packages/django/template/loader.py" in get_template 
    157. template, origin = find_template(template_name) 

File "/Library/Python/2.7/site-packages/django/template/loader.py" in find_template 
    128. loader = find_template_loader(loader_name) 

File "/Library/Python/2.7/site-packages/django/template/loader.py" in find_template_loader 
    93. module, attr = loader.rsplit('.', 1) 

這裏是我的視圖代碼:

from django.shortcuts import render_to_response 
from django.http import HttpResponse 

import datetime 
import sys 
import os 

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

def hours_ahead(request, offset): 
    offset = int(offset) 
    dt = datetime.datetime.now() + datetime.timedelta(hours=offset) 
    return render_to_response('plus.html', {'offset': offset, 'dt': dt}) 

這裏是我的urls.py

from django.conf.urls.defaults import * 
from dev2.views import * 

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

下面是settings.py

模板裝載機配置
TEMPLATE_LOADERS = (
    '/Users/some_user_name/Sites/djcode/dev2/template', 
) 

而這裏的模板HTML文件

<html><head></head><body>It is now {{ current_date }}.</body></html> 

回答

6

你設置了錯誤的事情settings.py中。 TEMPLATE_LOADERS適用於查找和加載模板的Python代碼。你想把你的目錄放到TEMPLATE_DIRS

+0

非常感謝。有用。猜猜我需要更仔細地閱讀手冊。 –