<table>
<tr>
{% for fields in field_list %}
<th>{{field
}}
{% endfor %}
{% for row in row_list %}
<tr>
{% for field
in field
_list %}
<td>{{row.field
}}
{% endfor %}
{% endfor %}
</table>
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c9e29d66-f93c-4fc4-ae9f-dbeae93a2e45%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
field is a string – a name of a field, field is not actually an attribute of row. You’ll need a template tag to get the attribute named field from row.
This StackOverflow question may help you:
--
Create a template tag like this (in yourproject/templatetags):
@register.filter
def keyvalue(dict, key):
return dict[key]
Usage in template:
{{dictionary|keyvalue:key_variable}}
def getattribute(value, arg):
"""Gets an attribute of an object dynamically from a string name"""
if hasattr(value, str(arg)):
return getattr(value, arg)
else
return ""
To post to this group, send email to djang...@googlegroups.com.
I would probably even simplify the code. Apparently, there’s a setting called TEMPLATE_STRING_IF_INVALID
def
getattribute(value,
arg):
"""Gets an attribute of an object dynamically from a string name"""
return
getattr(value,
arg, settings.TEMPLATE_STRING_IF_INVALID) or
settings.TEMPLATE_STRING_IF_INVALID
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2bf96986-c977-49bb-b71a-6d789a1c996b%40googlegroups.com.