Changes between Version 4 and Version 5 of TemplatePitfalls


Ignore:
Timestamp:
Aug 30, 2005, 3:52:13 PM (19 years ago)
Author:
Adrian Holovaty
Comment:

Removed incorrect section about is_anonymous in templates.

Legend:

Unmodified
Added
Removed
Modified
  • TemplatePitfalls

    v4 v5  
    1 Here's how to dodge some of the more obvious template pitfalls:
     1= Template pitfalls =
    22
     3Here's how to dodge some of the more obvious template pitfalls:
    34
    45== Debugging ==
     
    67Not a pitfall, but a tip:
    78
    8 Use {% debug %} in a template block if you want to know what is defined and can be used in a template.
     9Use {{{{% debug %}}}} in a template block if you want to know what is defined and can be used in a template.
    910
    1011The debug output is pretty ugly unless you look at it through View Source, or you can do it this way:
     
    2425}}}
    2526
    26 == Anonymity ==
    27 
    28 {{{user.is_anonymous}}} is a method, not an attribute, which makes it hard to test against in a template. Set your own context variable {{{is_anonymous}}}, instead.
    29 
    3027== Context variables and template inheritance ==
    3128
    32 To solve ''Anonymity'' above, it's handy to define a method each view can call to fill in its {{{Context}}} with the right variables. If you're inheriting templates, you should also do the same with the method. I've ended up with an {{{app_vars}}} method in each app's views module which calls {{{site_vars}}} in the site.
     29It's handy to define a method each view can call to fill in its {{{Context}}} with the right variables. If you're inheriting templates, you should also do the same with the method. I've ended up with an {{{app_vars}}} method in each app's views module which calls {{{site_vars}}} in the site.
    3330
    3431{{{site_vars}}} goes in {{{sitename/views/sitename.py}}} if you're trying to match the default shape of the application namespace, or in {{{sitename/views.py}}} if you're flattening it:
Back to Top