MCPcopy
hub / github.com/django/django / render

Method render

django/template/library.py:374–403  ·  view source on GitHub ↗

Render the specified template and context. Cache the template object in render_context to avoid reparsing and loading when used in a for loop.

(self, context)

Source from the content-addressed store, hash-verified

372 self.filename = filename
373
374 def render(self, context):
375 """
376 Render the specified template and context. Cache the template object
377 in render_context to avoid reparsing and loading when used in a for
378 loop.
379 """
380 resolved_args, resolved_kwargs = self.get_resolved_arguments(context)
381 _dict = self.func(*resolved_args, **resolved_kwargs)
382
383 t = context.render_context.get(self)
384 if t is None:
385 if isinstance(self.filename, Template):
386 t = self.filename
387 elif isinstance(getattr(self.filename, "template", None), Template):
388 t = self.filename.template
389 elif not isinstance(self.filename, str) and isinstance(
390 self.filename, Iterable
391 ):
392 t = context.template.engine.select_template(self.filename)
393 else:
394 t = context.template.engine.get_template(self.filename)
395 context.render_context[self] = t
396 new_context = context.new(_dict)
397 # Copy across the CSRF token, if present, because inclusion tags are
398 # often used for forms, and we need instructions for using CSRF
399 # protection to be as simple as possible.
400 csrf_token = context.get("csrf_token")
401 if csrf_token is not None:
402 new_context["csrf_token"] = csrf_token
403 return t.render(new_context)
404
405
406def parse_bits(

Callers

nothing calls this directly

Calls 7

select_templateMethod · 0.80
funcMethod · 0.45
getMethod · 0.45
get_templateMethod · 0.45
newMethod · 0.45
renderMethod · 0.45

Tested by

no test coverage detected