views:

129

answers:

1

I upgraded a working Django app to 1.1 and I now get a KeyError exception on a for loop!

Template error

In template /vol/.../templates/base_bbn.html, error at line 7
Caught an exception while rendering: 'django.contrib.comments.urls.'

You would think that there couldn't be a KeyError on a for loop like this because there would be a key for each item it iterates through.

{% block blog_class %}
{% for post in POSTS %}    # <-----------Template error on this line
 <p class="bbn-dateln">{{ post.publish|date:"Y F d" }

The actual exception is KeyError

File "/usr/lib/python2.5/site-packages/django/utils/importlib.py", line 36, in import_module
return sys.modules[name]
KeyError: 'django.contrib.comments.urls.'

Any suggestions on how to debug this? POSTS that I'm passing to this template to be rendered looks fine....

+1  A: 

Ok! I figured it out myself.

It seems that django.contrib.comments.urls in 1.1 now has a dependency on module dateutils that my python environment didn't have. Once I installed dateutils via easy_install, it started working again.

For some reason, the exception this caused bubbled up as a "template error" and "KeyError" on the django error page. It took some time in the python debugger to find the real cause

ראובן