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‘)
时间: 2024-10-23 22:37:27