[clug] dynamic inserts with django templates?

Paul Wayper paulway at mabula.net
Thu Dec 16 05:45:13 MST 2010

Hash: SHA1

On 12/15/2010 07:38 PM, Brendan Jurd wrote:
> On 15 December 2010 13:09, jm <jeffm at ghostgun.com> wrote:
>> If the main content is generated by the controller and the decoration
>> (header, footer, navbar, and menu) are common to most pages so you place
>> them in an inherited template. How do you generate the variables to be used
>> by the decoration? You don't what to repeat yourself by adding it to all the
>> actions in each controller.
> I write my pages as classes that all inherit from an abstract Page
> class.  The common context settings for the common nav elements are
> done there.  The templates are a mix of inheritance and includes.

Is that within Django?  Because it doesn't sound like the Django way.  Would
you like to give a Programming SIG talk on it? :-)

For part of your answer, Jeff, make sure you're using RequestContexts:

from django.template import RequestContext

# and in the view:
    return render_to_response('template.html', {
        'data'	: data,
    }, context_instance=RequestContext(request))

That way your templates can directly check the user object (e.g.

There must be a better way to do menus, and I see a few general ideas on the
Django website, but I get the feeling everyone implements their own - which is
not really the Django Way.

Have fun,


Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/


More information about the linux mailing list