Django中render_to_response和render的区别(转载)

转载地址:https://www.douban.com/note/278152737/

 

自django1.3开始:render()方法是render_to_response的一个崭新的快捷方式,前者会自动使用RequestContext。而后者必须coding出来,这是最明显的区别,当然前者更简洁。

    return render_to_response('blog_add.html',{'blog': blog, 'form': form, 'id': id, 'tag': tag},
                              context_instance=RequestContext(request))

    return render(request, 'blog_add.html', {'blog': blog, 'form': form, 'id': id, 'tag': tag})

 

locals()用法:locals()可以直接将函数中所有的变量全部传给模板。当然这可能会传递一些多余的参数,有点浪费内存的嫌疑。
    return render(request, 'blog_add.html',locals())

猜你喜欢

转载自blog.csdn.net/uwenhao2008/article/details/80624794