Whats the difference (in language a python/django noob can understand) in a view between render()
, render_to_response()
and direct_to_template()
?
e.g. from Nathan Borror's basic apps examples
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,
})
But I've also seen
return render_to_response(template_name, my_data_dictionary,
context_instance=RequestContext(request))
And
return direct_to_template(request, template_name, my_data_dictionary)
Whats the difference, what to use in any particular situation?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…