You have to write your own Template filters.
One that extracts all the attr names of an object - "allAttrs",
and one that gets the attr with a given name from an object with
obj.getattr() - "getobjattr"
In the template you just call these filters
{%for attr in obj | allAttrs %}
<p> {{attr}} = {{obj|getobjattr:attr}} </p>
{%endfor%}
There are template languages, like Mako, that allow more python code
to be inside the template.
Another method is to construct a dictionary from the obj.__dict__
Do not copy the attributes that are GAE specific like the attributes
that start with an underscore and all the callables, and then use this
dictionary in the django template
2010/4/11 deostroll <[email protected]>:
> I am dynamically creating some objects in my python code as follows:
> ---
> class MyObject(object):
> pass
>
> obj = MyObject()
>
> obj.attr1 = 'val1'
> obj.attr2 = 'val2'
> .
> .
> .
> obj.attrabc = 'valabc'
> ---
> I am looking to generate html below:
> ---
> <p> attr1 = val1 </p>
> <p> attr2 = val2 </p>
> .
> .
> .
> <p> attrabc = valabc </p>
> ---
> The challenge is getting to attribute names and the corresponding
> value of the attribute dynamically from within django templates. Is
> there anyway we can do this?
>
> --deostroll
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-appengine?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en.