码迷,mamicode.com
首页 > 其他好文 > 详细

Django源码分析——shotcuts

时间:2015-09-08 00:14:26      阅读:641      评论:0      收藏:0      [点我收藏+]

标签:

 1 def render(request, *args, **kwargs):
 2     """
 3     Returns a HttpResponse whose content is filled with the result of calling||返回的HttpResponse的内容充满了调用的结果
 4     django.template.loader.render_to_string() with the passed arguments. 
 5     Uses a RequestContext by default.   使用RequestContext默认情况下。
 6     """
 7     httpresponse_kwargs = {
 8         content_type: kwargs.pop(content_type, None),
 9         status: kwargs.pop(status, None),
10     }
11 

**kwargs  的用法是输入的参数变为一个字典
12 if context_instance in kwargs: 13 context_instance = kwargs.pop(context_instance) 14 if kwargs.get(current_app, None): 15 raise ValueError(If you provide a context_instance you must 16 set its current_app before calling render()) 17 else: 18 current_app = kwargs.pop(current_app, None) 19 context_instance = RequestContext(request, current_app=current_app) 20 21 kwargs[context_instance] = context_instance 22 23 return HttpResponse(loader.render_to_string(*args, **kwargs), 24 **httpresponse_kwargs)

 

from django.shotcuts import render

 

 1.*args :可以输入多个参数

my.HTML    博客参数  都是属于 args

技术分享 

 

(2)在字典里,in与has_key的用法是一样的,但是推荐用in  ,Python3 已经删除 has_key了

列如第12行

 

(3)字典的pop方法:  pop[‘key’]   把这个键的键和值都删除了;并且把他取出来

列如第8行,第13行

 

(4)raise的用法

a =10
if a:
    raise ValueError(a == 10)

 

技术分享

Django源码分析——shotcuts

标签:

原文地址:http://www.cnblogs.com/IDomyself/p/4790275.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!