title: Getting NameError for an exception handling
body: <p>I wanted to list an object(club) detail on a page by extracting its id from url and giving it to django models api. It is working when that id exist in the database. But when I try giving id in url which does not exist then the model api gives this error:</p>
  
  <blockquote>
    <blockquote>
      <blockquote>
        <p>club = Club.objects.get(id=8)
            Traceback (most recent call last):
              File "", line 1, in 
          File "/usr/local/lib/python2.7/dist-packages/django/db/models/manager.py", line 131, in get
            return self.get_query_set().get(*args, **kwargs)
          File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 366, in get
            % self.model._meta.object_name)
        DoesNotExist: Club matching query does not exist.</p>
      </blockquote>
    </blockquote>
  </blockquote>
  
  <p>So I added an exception handler for this error in my view. Here is the code:</p>
  
  <pre><code>def club_detail(request, offset):
      try:
          club_id = int(offset)
          club = Club.objects.get(id=club_id)
      except (ValueError, DoesNotExist):
          raise HTTP404()
      return render_to_response('home/club_detail.html', {'club': club }, context_instance = RequestContext(request))
  </code></pre>
  
  <p>But it is not catching DoesNotExist error and instead giving a NameError in browser:</p>
  
  <pre><code>NameError at /club/8/
    global name 'DoesNotExist' is not defined
    Request Method:   GET
    Request URL:  http://127.0.0.1:8000/club/8/
    Django Version:   1.4.1
    Exception Type:   NameError
    Exception Value:  
    global name 'DoesNotExist' is not defined
  </code></pre>
  
  <p>How can I make it working? Thanks in advance</p>