python学习3-python views.py的返回值

 

2.首先要说明一点是,对于HttpRequest对象来说,是Django自己创建的,但是HttpResponse就必须要我们自己创建。注意每个view方法都必须返回一个HttpResponse对象,HttpResonse对象也是在Django.http里面,这里我们看看之前一直用到的render函数:

 

def render(request, template_name, context=None, context_instance=_context_instance_undefined, content_type=None, status=None, current_app=_current_app_undefined, dirs=_dirs_undefined, dictionary=_dictionary_undefined, using=None):
...........省略............ return HttpResponse(content, content_type, status) # 可以看到最后返回的就是个HttpResponse对象

posted on 2018-11-29 11:27  admingy  阅读(218)  评论(0编辑  收藏  举报

导航