Thursday 12 September 2013

Including a small app into a Django template

Including a small app into a Django template

I am starting out in Django and haven't been able to find an answer to
this question in tutorials or elsewhere. It seems like a simple feature,
so I wonder if I am not understanding - so anyone that can explain it
clearly would be greatly appreciated.
Say I have a site with 5 different pages via Django templates. If I write
a small app that renders a poll (like the django tutorial), but I don't
want that app to have its own url, just to feature, for example, in a
sidebar of 2 of the 5 pages. The poll app has nothing to do with the other
pages/apps.
My first thought was to go to those 2 pages' templates and include the
template for the poll app - {% include "poll.html" %} ... I then found out
this renders only the html as is, but I need to reference the database
models to render a list of polls.
Inheritance doesn't quite make sense to me in this instance...
So, what would be the best practice way of doing this? For me, this is the
whole idea of plug and play apps that Django is good for, but can't figure
out how to just plug it in to other templates! I really just want to know
the simple theory behind doing this, because it seems like a key feature.
Thanks!

No comments:

Post a Comment