Ticket #3544: 3544.contexttemplatecache.diff
File 3544.contexttemplatecache.diff, 2.6 KB (added by , 16 years ago) |
---|
-
django/template/context.py
13 13 dict_ = dict_ or {} 14 14 self.dicts = [dict_] 15 15 self.autoescape = autoescape 16 self.template_cache = {} 16 17 17 18 def __repr__(self): 18 19 return repr(self.dicts) … … 64 65 "Like dict.update(). Pushes an entire dictionary's keys and values onto the context." 65 66 self.dicts = [other_dict] + self.dicts 66 67 return other_dict 68 69 def get_template(self, template_name): 70 if not template_name in self.template_cache: 71 from django.template.loader import get_template 72 self.template_cache[template_name] = get_template(template_name) 73 return self.template_cache[template_name] 67 74 68 75 # This is a function rather than module-level procedural code because we only 69 76 # want it to execute if somebody uses RequestContext. -
django/template/loader_tags.py
92 92 parent_block.nodelist = block_node.nodelist 93 93 return compiled_parent.render(context) 94 94 95 class ConstantIncludeNode(Node):96 def __init__(self, template_path):97 try:98 t = get_template(template_path)99 self.template = t100 except:101 if settings.TEMPLATE_DEBUG:102 raise103 self.template = None104 105 def render(self, context):106 if self.template:107 return self.template.render(context)108 else:109 return ''110 111 95 class IncludeNode(Node): 112 96 def __init__(self, template_name): 113 97 self.template_name = Variable(template_name) … … 115 99 def render(self, context): 116 100 try: 117 101 template_name = self.template_name.resolve(context) 118 t = get_template(template_name)102 t = context.get_template(template_name) 119 103 return t.render(context) 120 104 except TemplateSyntaxError, e: 121 105 if settings.TEMPLATE_DEBUG: … … 178 162 bits = token.contents.split() 179 163 if len(bits) != 2: 180 164 raise TemplateSyntaxError, "%r tag takes one argument: the name of the template to be included" % bits[0] 181 path = bits[1]182 if path[0] in ('"', "'") and path[-1] == path[0]:183 return ConstantIncludeNode(path[1:-1])184 165 return IncludeNode(bits[1]) 185 166 186 167 register.tag('block', do_block)