Newbie Question:
I have a dictionary rendering with extra_Context from a method defined in views.py
My views:
extra_context = {
'comment': comment
}
return direct_to_template(request, 'events/comment_detail.html', extra_context)
If i print the comment the it print like this:
[{'comment': u'first', 'user': 2}, {'comment': u'second', 'user': 2}]
I want to pass this dictionary to my template. I tried with this following code:
<tbody>
{% for obj in comment %}
{% for key,val in obj.items %}
<tr class="{% cycle 'odd' 'even' %}">
<td> {{val}}</td>
</tr>
{% endfor %}
{% endfor %}
</tbody>
It prints :
first
2
second
2
I want in this way:
first 2
second 2
..and so on
What should i add it to get like above ?
Updated!
def comment_detail(request, object_id):
comment_obj = EventComment.objects.filter(event = object_id)
comment = comment_obj.values('comment','user')
extra_context = {
'comment': comment
}
return direct_to_template(request, 'events/comment_detail.html', extra_context)
comment_detail.html
<form action="" method="POST">
<table>
<thead>
<tr><th>{% trans "Comments" %}</th><th>{% trans "Timestamp "%}<th>{% trans "User" %}</th></tr>
</thead>
<tbody>
{% if comments %}
{% for com in comment %}
<td> {{com.comment}}</enter code heretd>
<td> {{com.user}}</td>
{% endfor %}
{% else %}
<td> No comments </td>
{% endif %}
</tr>
</tbody>
</table>
</form>
You don’t need that nested
foriteratingk,v. I just tried this:View:
Template: