Hi, I'm a newbie in Django. I got I problem looks like below:

============== contents.py ======================

from testcms.contents.models import *

class Contents(UserDict):
    def get_contents_list(self):

    contents = Contents.objects.all()
    for content in contents:
        author = Users.objects.get(userid = content.author_id)
        type = ContentTypes.objects.get(type_id = content.type_id)
        relative = ContentsRelative.objects.filter(content_id =
content.content_id).count()

        self[content.id] = {
                    'content_id' : content.id,
                    'title' : content.name,
                    'type' : type.name,
                    'relative' : relative,
        }

    return self

=========== views.py ==================

def contents_list(request):
    content = Contents()
    contents = content.get_contents_list()

    return render_to_response("show.html", {'contents' : contents})

=========== show.html =================

                                {% for content in contents %}
                                        <td valign="top"><a href="#">{{ 
content.title }}</a></td>
                                        <td valign="top">content.type</td>
                                        <td valign="top">content.relative </td>
                                {% endfor %}

=====================================

The data struct of content is like:

{346L: {'type': u'Function', 'relative': 0, 'content_id': 346L,
'title': u'Config Diff Interface'}}

But when I run my program, it report:

TemplateSyntaxError at /plans/
Caught an exception while rendering: 0

Original Traceback (most recent call last):
  File "/Library/Python/2.5/site-packages/Django-1.0_final-py2.5.egg/
django/template/debug.py", line 71, in render_node
    result = node.render(context)
  File "/Library/Python/2.5/site-packages/Django-1.0_final-py2.5.egg/
django/template/defaulttags.py", line 130, in render
    for i, item in enumerate(values):
  File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/UserDict.py", line 22, in __getitem__
    raise KeyError(key)
KeyError: 0

How can I use 2D dictionary data struct like upon in tempmlate ?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to