5.6.3 Shortening Code with render()

Before introducing the render_to_response() shortcut, our /organizer/views.py read as shown in Example 5.27.

Example 5.27: Project Code

organizer/views.py in 4d36d603db

 1  from django.http.response import HttpResponse  2  from django.shortcuts import get_object_or_404  3  from django.template import Context, loader  4  5  from .models import Tag  6  7  8  def homepage(request):  9      tag_list = Tag.objects.all() 10      template = loader.get_template( 11          'organizer/tag_list.html') 12      context = Context({'tag_list': tag_list}) 13      output = template.render(context) 14      return HttpResponse(output) 15 16 17  def tag_detail(request, slug): 18      tag = get_object_or_404( ...

Get Django Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.