我正在学习Django的一些教程,用于即将开展的项目,我无法正确加载模板。调试模式返回“ValueError”,表示“需要多于1个值才能解压”。我正在运行Django的捆绑服务器。知道问题是什么?任何帮助表示赞赏。
这是追踪:
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>
答案 0 :(得分:6)
你在settings.py中设置了错误的内容。 TEMPLATE_LOADERS
用于查找和加载模板的Python代码。您希望将目录放入TEMPLATE_DIRS
。