title: Tango with Django 1.9 on Django 2.0 - "list indices must be integers or slices, not str"
body: <p>I am, probably stupidly, attempting to go through Tango with Django 1.9 on newly released Django 2.0. I am up to <a href="https://github.com/leifos/tango_with_django_19/blob/master/manuscript/chapter6-models-templates-views.md" rel="nofollow noreferrer">chapter 6</a> and am getting the following error.</p>
  
  <p><a href="https://i.stack.imgur.com/iUVGb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iUVGb.png" alt="enter image description here"></a> </p>
  
  <p>The error pertains to my views.py file (below) with the lines, </p>
  
  <pre><code>context_dict['pages'] = pages
  context_dict['category'] = category
  </code></pre>
  
  <p>seemingly the culprits. Has the way in which variables are assigned to dictionaries changed in Django 2.0 or is this a Python issue? Can provide code from all other application files. </p>
  
  <p><strong>Views.py</strong></p>
  
  <pre><code>from django.shortcuts import render
  from rango.models import Category, Page
  
  def index(request):
  
      category_list = Category.objects.order_by('-likes')[:5]
      context_dict = {'categories':category_list}
      return render(request, 'rango/index.html', context=context_dict)
  
  def about(request):
      return render(request, 'rango/about.html')
  
  def show_category(request, category_name_slug):
      context_dict = []
  
      try:
  
          category = Category.objects.get(slug=category_name_slug)
  
          pages = Page.objects.filter(category=category)
  
          context_dict['pages'] = pages
          context_dict['category'] = category
  
      except Category.DoesNotExist:
          context_dict['category'] = None
          context_dict['pages'] = None
  
      return render(request, 'rango/category.html', context_dict)
  </code></pre>
  
  <p><strong>Models.py</strong></p>
  
  <pre><code>from django.db import models
  from django.contrib import admin
  from django.template.defaultfilters import slugify
  
  # Create your models here.
  
  class Category(models.Model):
      name = models.CharField(max_length=128, unique=True)
      views = models.IntegerField(default=0)
      likes = models.IntegerField(default=0)
      slug = models.SlugField(unique=True)
  
      def save(self, *args, **kwargs):
          self.slug = slugify(self.name)
          super(Category,self).save(*args, **kwargs)
  
      class Meta:
          verbose_name_plural = 'Categories'
  
      def __str__(self):
          return self.name
  
  
  class Page(models.Model):
      category = models.ForeignKey(Category, on_delete=models.PROTECT)
      title = models.CharField(max_length=128)
      url = models.URLField()
      views = models.IntegerField(default=0)
      def __str__(self): # For Python 2, use __unicode__ too
      return self.title
  
  class PageAdmin(admin.ModelAdmin):
      list_display = ('title','category','url')
  </code></pre>
  
  <p><strong>Pages (from admin page)</strong>
  <a href="https://i.stack.imgur.com/peM04.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/peM04.png" alt="Pages (from admin page)"></a></p>