from django.http import HttpResponse
from django.template import RequestContext, loader

from orders.models import Item

def index(request):
    item_list = Item.objects.all()
    template = loader.get_template('orders/index.html')
    context = RequestContext(request, {
        'item_list': item_list,
    })
    return HttpResponse(template.render(context))

from django.shortcuts import render

from orders.models import Item

def index(request):
    item_list = Item.objects.all()
    context = {'item_list': item_list}
    return render(request, 'orders/index.html', context)

Use render in the index view
Use render in the index view

+ from django.shortcuts import render
- from django.http import HttpResponse
- from django.template import RequestContext, loader
  
  from orders.models import Item
  
  def index(request):
      item_list = Item.objects.all()
-     template = loader.get_template('orders/index.html')
-     context = RequestContext(request, {
-         'item_list': item_list,
+     context = {'item_list': item_list}
+     return render(request, 'orders/index.html', context)
-     })
-     return HttpResponse(template.render(context))
  
Use render in the index view
## Code Before:
from django.http import HttpResponse
from django.template import RequestContext, loader

from orders.models import Item

def index(request):
    item_list = Item.objects.all()
    template = loader.get_template('orders/index.html')
    context = RequestContext(request, {
        'item_list': item_list,
    })
    return HttpResponse(template.render(context))

## Instruction:
Use render in the index view
## Code After:
from django.shortcuts import render

from orders.models import Item

def index(request):
    item_list = Item.objects.all()
    context = {'item_list': item_list}
    return render(request, 'orders/index.html', context)
