title: Django will not redirect to 404 in try except statement
body: <p>I'm currently in the process of learning the Django library and am stumped
  because I am receiving a DoesNotExist error (status = 500) instead of a 404 page error,
  I tried turning debug = False, however all I received was a 500 status page instead.</p>
  
  <pre><code>class CategoryView(generic.ListView):
      model = Category
      template_name = 'rango/category.html'
      allow_empty = False
  
      try:
          def get_context_data(self, *args, **kwargs):
              context = super(CategoryView, self).get_context_data(*args, **kwargs)
              category_name = decode_url(self.kwargs['category_name_url'])
              category = Category.objects.get(name = category_name)
              pages = Page.objects.filter(category = category)
              context['category'] = category
              context['pages'] = pages
              return context   
      except Category.DoesNotExist:
          raise Http404
  </code></pre>
  
  <p>Traceback:</p>
  
  <blockquote>
    <p>DoesNotExist at /rango/category/Perl/</p>
    
    <p>Category matching query does not exist.</p>
    
    <p>Traceback: File
    "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in
    get_response
      114.                     response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/Library/Python/2.7/site-packages/django/views/generic/base.py" in
    view
      69.             return self.dispatch(request, *args, **kwargs) File "/Library/Python/2.7/site-packages/django/views/generic/base.py" in
    dispatch
      87.         return handler(request, *args, **kwargs) File "/Library/Python/2.7/site-packages/django/views/generic/list.py" in
    get
      152.         context = self.get_context_data() File "/Users/justahack/Documents/Python/tango_with_django_project/rango/views.py"
    in get_context_data
      47.             category = Category.objects.get(name = category_name) File
    "/Library/Python/2.7/site-packages/django/db/models/manager.py" in get
      151.         return self.get_queryset().get(*args, **kwargs) File "/Library/Python/2.7/site-packages/django/db/models/query.py" in get
      307.                 self.model._meta.object_name)</p>
    
    <p>Exception Type: DoesNotExist at /rango/category/Perl/ Exception Value:
    Category matching query does not exist.</p>
  </blockquote>
  
  <p>Any help is much appreciated.  </p>