Ticket #6516: test.py

File test.py, 894 bytes (added by Wayne K. Werner, 17 years ago)

Demonstration of the bug.

Line 
1import django.template.loader
2from django.template import Template, Context
3from django.conf import settings
4settings.configure(TEMPLATE_DEBUG='DEBUG')
5
6t1 = Template('{% block content %}t1{% endblock %}')
7t2 = Template('{% extends base %}{% block content %}t2{{block.super}}{% endblock %}')
8
9def render(t_name, context):
10 print "%s.render() %s" % (t_name, globals()[t_name].render(context))
11
12c = Context(dict(base=t1))
13
14print "content block in t1 is modified by rendering through t2"
15render('t1', c)
16render('t2', c)
17render('t1', c)
18
19t1 = Template('{% block content %}t1{% endblock %}')
20t2 = Template('{% extends base1 %}')
21t3 = Template('{% extends base2 %}{% block content %}t3{% endblock %}')
22
23c = Context(dict(base1=t1, base2=t2))
24
25print "\ncontent block added to t2 when rendering through t3"
26render('t1', c)
27render('t2', c)
28render('t3', c)
29render('t2', c)
Back to Top