Joseph Lee
Joseph Lee

Reputation: 13

Django View ValueError when render_to_response

I am going through some tutorials of learning Django for an upcoming project, and I could not load templates correctly. The debug mode returns a "ValueError" saying that it "need more than 1 value to unpack". I am running Django's bundled server. Any idea what's the problem? Any help is appreciated.

Here's the trace:

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)

Here's my view code:

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})

Here's my 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),
)

Here's the template loader config in settings.py

TEMPLATE_LOADERS = (
    '/Users/some_user_name/Sites/djcode/dev2/template',
)

And here's the template html file

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

Upvotes: 1

Views: 1495

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599590

You've set the wrong thing in settings.py. TEMPLATE_LOADERS is for Python code that finds and loads templates. You want to put your directory into TEMPLATE_DIRS.

Upvotes: 6

Related Questions