Django Source Analysis--loader.py

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.