You may pass a dictionary of album properties to the template like this:

def album(request, album_id):
       a = Album.objects.get(id=album_id)
       return render_to_response('fc/album.html', {'album': a,
'album_dict': a.__dict__})

and then use pprint filter to read the properties in the template:
{{ album_dict|pprint|escape }}

The filter "escape" changes all < to &lt; and > to &gt; and makes it
possible to read strings like <Album: Youngbloods> not viewing the
source.

Regards,
Aidas Bendoraitis aka Archatas


On 12/19/06, Nathan R. Yergler <[EMAIL PROTECTED]> wrote:
>
> radioflyer wrote:
> > ...I'm new to Python and still thinking like a PHP user I'm afraid...
> >
> > I've found a number of posts about dumping debug info to a template,
> > but I'm still a little confused. Maybe  I don't understand the nature
> > of the 'context' returned from my view.
> >
> > If I have this view:
> > def album(request, album_id):
> >       a = Album.objects.get(id=album_id)
> >       return render_to_response('fc/album.html', {'album': a})
> >
> > {% debug %} outputs Album.self, something like:
> >
> > <pre>
> > {'album': <Album: Youngbloods>}
> > ...the rest...
> > </pre>
> >
> > I was expecting something to the effect:
> > album.label:
> > album.catalog_number:
> > album.recording_date: etc.
> >
> > Those values are available. (The template is displaying them
> > correctly.) I just thought I would be able to see the context variable
> > values dumped out. Especially related values if I had requested them in
> > the view.
>
> You *are* seeing the context variable values :).  The distinction here
> is that instead of 3 different variables (album.label,
> album.catalog_number, etc) in the context, you're dealing with a single
> object -- album -- that has a number of properties.  If you really
> wanted to see that sort of information you'd need to pass it into your
> template from the view as individual values (in the call to
> render_to_response).
>
> NRY
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
 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