From django.template Import Loader
1 defRender_to_string (Template_name, Dictionary=none, context_instance=None):2 """3 Loads the given template_name and renders it with the given dictionary as4 context. The Template_name is a string to load a single template using5 Get_template, or it may is a tuple to use select_template to find one of6 The templates in the list. Returns a string.7 """8Dictionary = Dictionaryor {}9 ifisinstance (template_name, (list, tuple)):Tent =select_template (template_name) One Else: At =get_template (template_name) - if notcontext_instance: - returnT.render (Context (dictionary)) the #Add the dictionary to the context stack, ensuring it gets removed again - #To keep the context_instance of the same state it started in. - context_instance.update (dictionary) - Try: + returnT.render (context_instance) - finally: +Context_instance.pop ()
Note: "" "
3 load given template_name rendered with the given dictionary
4 context. template_name may be a string that loads a single template using
5 Get_template, or it might be a tuple using select_template to discover one
6 List of templates. returns a string.
”“”
Three parameters:
Template_name
Dictionary=none
Context_instance=None
8:dictionary = Dictionary or {} this definition does not understand
9: If the Template_name type is a list, or a tuple,
Just call Select_template ()
Otherwise, call get_template (template_name)
Not
Return T.render (Context (dictionary))
Django Source Analysis--loader.py