Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (47.6k points)
edited by

What's 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,



  # ... 

  return render(request, template_name, { 

        'form': form, 

        'comment': comment, 


But I've also seen

return render_to_response(template_name,          my_data_dictionary,



return direct_to_template(request, template_name, 


What's the difference, what to use in any particular situation?

1 Answer

0 votes
by (106k points)

So there is really no difference between render_to_response except it wraps your context making the template pre-processors work:-

def render(request, *args, **kwargs): 

""" Simple wrapper for render_to_response. """

kwargs['context_instance'] = RequestContext(request) 

return render_to_response(*args, **kwargs)

Related questions

Browse Categories