diff --git a/django/template/loader_tags.py b/django/template/loader_tags.py
index d295d05..6dbe49f 100644
a
|
b
|
from django.template.loader import get_template
|
5 | 5 | from django.utils.safestring import mark_safe |
6 | 6 | from django.utils import six |
7 | 7 | |
| 8 | from collections import defaultdict |
| 9 | |
8 | 10 | register = Library() |
9 | 11 | |
10 | 12 | BLOCK_CONTEXT_KEY = 'block_context' |
… |
… |
class ExtendsError(Exception):
|
15 | 17 | class BlockContext(object): |
16 | 18 | def __init__(self): |
17 | 19 | # Dictionary of FIFO queues. |
18 | | self.blocks = {} |
| 20 | self.blocks = defaultdict(list) |
19 | 21 | |
20 | 22 | def add_blocks(self, blocks): |
21 | 23 | for name, block in six.iteritems(blocks): |
22 | | if name in self.blocks: |
23 | | self.blocks[name].insert(0, block) |
24 | | else: |
25 | | self.blocks[name] = [block] |
| 24 | self.blocks[name].insert(0, block) |
26 | 25 | |
27 | 26 | def pop(self, name): |
28 | 27 | try: |
29 | 28 | return self.blocks[name].pop() |
30 | | except (IndexError, KeyError): |
| 29 | except IndexError: |
31 | 30 | return None |
32 | 31 | |
33 | 32 | def push(self, name, block): |
… |
… |
class BlockContext(object):
|
36 | 35 | def get_block(self, name): |
37 | 36 | try: |
38 | 37 | return self.blocks[name][-1] |
39 | | except (IndexError, KeyError): |
| 38 | except IndexError: |
40 | 39 | return None |
41 | 40 | |
42 | 41 | class BlockNode(Node): |