= Template pitfalls = Here's how to dodge some of the more obvious template pitfalls: == Debugging == Not a pitfall, but a tip: Use {{{{% debug %}}}} in a template block if you want to know what is defined and can be used in a template. The debug output is pretty ugly unless you look at it through View Source, or you can do it this way: {{{ {% filter linebreaks %} {% debug %} {% endfilter %} }}} or more simply: {{{
{% debug %}}}} == custom context variables for generic views == More advanced versions of the base template (mine is {{{base.html}}}, following the model set in the administration interface) might need a consistent set of context variables generated on the fly based on the identity of the current user, what they're doing, what's happening elsewhere on the site, and so on. If you're using generic views, though, there's no obvious way to make these context variables available. The solution is to use [http://www.djangoproject.com/documentation/templates_python/#writing-custom-template-tags custom template tags], which can modify a page's context variables on the fly. If your needs are middling simple, or you don't want to have to write your own custom template tag from scratch, I've developed a generic option: [http://www.deadlybloodyserious.com/categories/django/2005/09/06.html vars], which defines a fairly generic {{{pushvars}}} tag that calls the function of your choice and pushes its results into the current context. I'm posting this to atone for my previous crummy advice on this Wiki page. {{{- garthk}}}