Django

Code

Changeset 6673

Show
Ignore:
Timestamp:
11/14/07 15:07:27 (1 year ago)
Author:
mtredinnick
Message:

Content coming via {{ block.super }} is always going to be correctly escaped
already. We mark it as safe so that template authors don't need to.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/template/loader_tags.py

    r6399 r6673  
    33from django.template.loader import get_template, get_template_from_string, find_template_source 
    44from django.conf import settings 
     5from django.utils.safestring import mark_safe 
    56 
    67register = Library() 
     
    2728    def super(self): 
    2829        if self.parent: 
    29             return self.parent.render(self.context
     30            return mark_safe(self.parent.render(self.context)
    3031        return '' 
    3132 
  • django/trunk/docs/templates.txt

    r6671 r6673  
    281281      the ``{{ block.super }}`` variable will do the trick. This is useful 
    282282      if you want to add to the contents of a parent block instead of 
    283       completely overriding it. 
     283      completely overriding it. Data inserted using ``{{ block.super }}`` will 
     284      not be automatically escaped (see the `next section`_), since it was 
     285      already escaped, if necessary, in the parent template. 
    284286 
    285287    * For extra readability, you can optionally give a *name* to your 
     
    299301two similarly-named ``{% block %}`` tags in a template, that template's parent 
    300302wouldn't know which one of the blocks' content to use. 
     303 
     304.. _next section: #automatic-html-escaping 
    301305 
    302306Automatic HTML escaping 
  • django/trunk/tests/regressiontests/templates/tests.py

    r6671 r6673  
    618618 
    619619            # Standard template with no inheritance 
    620             'inheritance01': ("1{% block first %}_{% endblock %}3{% block second %}_{% endblock %}", {}, '1_3_'), 
     620            'inheritance01': ("1{% block first %}&{% endblock %}3{% block second %}_{% endblock %}", {}, '1&3_'), 
    621621 
    622622            # Standard two-level inheritance 
     
    627627 
    628628            # Two-level with no redefinitions on second level 
    629             'inheritance04': ("{% extends 'inheritance01' %}", {}, '1_3_'), 
     629            'inheritance04': ("{% extends 'inheritance01' %}", {}, '1&3_'), 
    630630 
    631631            # Two-level with double quotes instead of single quotes 
     
    636636 
    637637            # Two-level with one block defined, one block not defined 
    638             'inheritance07': ("{% extends 'inheritance01' %}{% block second %}5{% endblock %}", {}, '1_35'), 
     638            'inheritance07': ("{% extends 'inheritance01' %}{% block second %}5{% endblock %}", {}, '1&35'), 
    639639 
    640640            # Three-level with one block defined on this level, two blocks defined next level 
     
    642642 
    643643            # Three-level with second and third levels blank 
    644             'inheritance09': ("{% extends 'inheritance04' %}", {}, '1_3_'), 
     644            'inheritance09': ("{% extends 'inheritance04' %}", {}, '1&3_'), 
    645645 
    646646            # Three-level with space NOT in a block -- should be ignored 
    647             'inheritance10': ("{% extends 'inheritance04' %}      ", {}, '1_3_'), 
     647            'inheritance10': ("{% extends 'inheritance04' %}      ", {}, '1&3_'), 
    648648 
    649649            # Three-level with both blocks defined on this level, but none on second level 
     
    657657 
    658658            # A block defined only in a child template shouldn't be displayed 
    659             'inheritance14': ("{% extends 'inheritance01' %}{% block newblock %}NO DISPLAY{% endblock %}", {}, '1_3_'), 
     659            'inheritance14': ("{% extends 'inheritance01' %}{% block newblock %}NO DISPLAY{% endblock %}", {}, '1&3_'), 
    660660 
    661661            # A block within another block 
     
    675675 
    676676            # Two-level inheritance with {{ block.super }} 
    677             'inheritance20': ("{% extends 'inheritance01' %}{% block first %}{{ block.super }}a{% endblock %}", {}, '1_a3_'), 
     677            'inheritance20': ("{% extends 'inheritance01' %}{% block first %}{{ block.super }}a{% endblock %}", {}, '1&a3_'), 
    678678 
    679679            # Three-level inheritance with {{ block.super }} from parent 
     
    681681 
    682682            # Three-level inheritance with {{ block.super }} from grandparent 
    683             'inheritance22': ("{% extends 'inheritance04' %}{% block first %}{{ block.super }}a{% endblock %}", {}, '1_a3_'), 
     683            'inheritance22': ("{% extends 'inheritance04' %}{% block first %}{{ block.super }}a{% endblock %}", {}, '1&a3_'), 
    684684 
    685685            # Three-level inheritance with {{ block.super }} from parent and grandparent 
    686             'inheritance23': ("{% extends 'inheritance20' %}{% block first %}{{ block.super }}b{% endblock %}", {}, '1_ab3_'), 
     686            'inheritance23': ("{% extends 'inheritance20' %}{% block first %}{{ block.super }}b{% endblock %}", {}, '1&ab3_'), 
    687687 
    688688            # Inheritance from local context without use of template loader