[documentos]defget_template(template_name,dirs=_dirs_undefined,using=None):""" Loads and returns a template for the given name. Raises TemplateDoesNotExist if no such template exists. """chain=[]engines=_engine_list(using)forengineinengines:try:# This is required for deprecating the dirs argument. Simply# return engine.get_template(template_name) in Django 1.10.ifisinstance(engine,DjangoTemplates):returnengine.get_template(template_name,dirs)elifdirsisnot_dirs_undefined:warnings.warn("Skipping template backend %s because its get_template ""method doesn't support the dirs argument."%engine.name,stacklevel=2)else:returnengine.get_template(template_name)exceptTemplateDoesNotExistase:chain.append(e)raiseTemplateDoesNotExist(template_name,chain=chain)

[documentos]defselect_template(template_name_list,dirs=_dirs_undefined,using=None):""" Loads and returns a template for one of the given names. Tries names in order and returns the first template found. Raises TemplateDoesNotExist if no such template exists. """chain=[]engines=_engine_list(using)fortemplate_nameintemplate_name_list:forengineinengines:try:# This is required for deprecating the dirs argument. Simply# use engine.get_template(template_name) in Django 1.10.ifisinstance(engine,DjangoTemplates):returnengine.get_template(template_name,dirs)elifdirsisnot_dirs_undefined:warnings.warn("Skipping template backend %s because its get_template ""method doesn't support the dirs argument."%engine.name,stacklevel=2)else:returnengine.get_template(template_name)exceptTemplateDoesNotExistase:chain.append(e)iftemplate_name_list:raiseTemplateDoesNotExist(', '.join(template_name_list),chain=chain)else:raiseTemplateDoesNotExist("No template names provided")

[documentos]defrender_to_string(template_name,context=None,context_instance=_context_instance_undefined,dirs=_dirs_undefined,dictionary=_dictionary_undefined,request=None,using=None):""" Loads a template and renders it with a context. Returns a string. template_name may be a string or a list of strings. """if(context_instanceis_context_instance_undefinedanddirsis_dirs_undefinedanddictionaryis_dictionary_undefined):# No deprecated arguments were passed - use the new code pathifisinstance(template_name,(list,tuple)):template=select_template(template_name,using=using)else:template=get_template(template_name,using=using)returntemplate.render(context,request)else:chain=[]# Some deprecated arguments were passed - use the legacy code pathforenginein_engine_list(using):try:# This is required for deprecating properly arguments specific# to Django templates. Remove Engine.render_to_string() at the# same time as this code path in Django 1.10.ifisinstance(engine,DjangoTemplates):ifrequestisnotNone:raiseValueError("render_to_string doesn't support the request argument ""when some deprecated arguments are passed.")# Hack -- use the internal Engine instance of DjangoTemplates.returnengine.engine.render_to_string(template_name,context,context_instance,dirs,dictionary)elifcontext_instanceisnot_context_instance_undefined:warnings.warn("Skipping template backend %s because its render_to_string ""method doesn't support the context_instance argument."%engine.name,stacklevel=2)elifdirsisnot_dirs_undefined:warnings.warn("Skipping template backend %s because its render_to_string ""method doesn't support the dirs argument."%engine.name,stacklevel=2)elifdictionaryisnot_dictionary_undefined:warnings.warn("Skipping template backend %s because its render_to_string ""method doesn't support the dictionary argument."%engine.name,stacklevel=2)exceptTemplateDoesNotExistase:chain.append(e)continueiftemplate_name:ifisinstance(template_name,(list,tuple)):template_name=', '.join(template_name)raiseTemplateDoesNotExist(template_name,chain=chain)else:raiseTemplateDoesNotExist("No template names provided")

def_engine_list(using=None):returnengines.all()ifusingisNoneelse[engines[using]]classBaseLoader(base.Loader):_accepts_engine_in_init=Falsedef__init__(self,*args,**kwargs):warnings.warn("django.template.loader.BaseLoader was superseded by ""django.template.loaders.base.Loader.",RemovedInDjango110Warning,stacklevel=2)super(BaseLoader,self).__init__(*args,**kwargs)classLoaderOrigin(six.with_metaclass(DeprecationInstanceCheck,Origin)):alternative='django.template.Origin'deprecation_warning=RemovedInDjango20Warning