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