Django Source Analysis--shotcuts

Source: Internet
Author: User

1 defRender (Request, *args, * *Kwargs):2     """3 Returns a httpresponse whose content is filled with the result of Calling| | The contents of the returned HttpResponse are filled with the result of the call4 django.template.loader.render_to_string () with the passed arguments.5 Uses a requestcontext by default. Use RequestContext by default. 6     """7Httpresponse_kwargs = {8         'Content_Type': Kwargs.pop ('Content_Type', None),9         'Status': Kwargs.pop ('Status', None),Ten     } One 

* *Kwargs The usage is that the input parameter becomes a dictionary
A if 'context_instance' inchKwargs: -Context_instance = Kwargs.pop ('context_instance') - ifKwargs.get ('Current_app', None): the RaiseValueError ('If You provide a context_instance you must' - 'set its current_app before calling render ()') - Else: -Current_app = Kwargs.pop ('Current_app', None) +Context_instance = RequestContext (Request, current_app=Current_app) - +kwargs['context_instance'] =context_instance A at returnHttpResponse (loader.render_to_string (*args, * *Kwargs), -**httpresponse_kwargs)

From django.shotcuts Import Render

1.*args: Multiple parameters can be entered

My. HTML Blog parameters are all part of the args


(2) in the dictionary, in and Has_key usage is the same, but recommended in, Python3 has deleted Has_key

GCA Line 12th

(3) The Pop method of the dictionary: pop[' key ' removes the key and the value of the key; and takes him out.

GCA Line 8th, line 13th

(4) Usage of raise

A =10if  A:    raise valueerror ('a = = ten')

Django Source Analysis--shotcuts

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.