1

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>
0

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks so much. It works. Guess I need to read the manual more carefully.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.