在一个视图中,render()
, render_to_response()
和direct_to_template()
之间有什么区别(用python/django新手能理解的语言)?
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,
})
但我也看到过
return render_to_response(template_name, my_data_dictionary,
context_instance=RequestContext(request))
和
return direct_to_template(request, template_name, my_data_dictionary)
有什么不同,在特定情况下用什么?