相关疑难解决方法(0)

Django - render(),render_to_response()和direct_to_template()之间有什么区别?

最新的差值(在语言蟒/ django的小白可以理解)在之间的视图render(),render_to_response()direct_to_template()

例如来自Nathan Borror的基本应用示例

def comment_edit(request, object_id, template_name='comments/edit.html'):
    comment = get_object_or_404(Comment, pk=object_id, user=request.user)
    # ...
    return render(request, template_name, {
        'form': form,
        'comment': comment,
    })
Run Code Online (Sandbox Code Playgroud)

但我也看到了

    return render_to_response(template_name, my_data_dictionary,
              context_instance=RequestContext(request))
Run Code Online (Sandbox Code Playgroud)

    return direct_to_template(request, template_name, my_data_dictionary)
Run Code Online (Sandbox Code Playgroud)

什么区别,在任何特定情况下使用什么?

python django

231
推荐指数
5
解决办法
10万
查看次数

标签 统计

django ×1

python ×1