Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 574619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:51:01+00:00 2026-05-13T13:51:01+00:00

All the time in Django I see DoesNotExist being raised like in db.models.fields.related.py .

  • 0

All the time in Django I see DoesNotExist being raised like in db.models.fields.related.py. Not ObjectDoesNotExist which is defined in django.core.exceptions, but just DoesNotExist. Where is this exception class defined, or am I not fully understanding exceptions? I’ve checked that it’s not in exceptions (at least not that I know of). I’m confused obviously.

Note: It also comes free, as an attribute of a model sub-class instance, like `self.someforeignkey.DoesNotExist. How is this possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T13:51:02+00:00Added an answer on May 13, 2026 at 1:51 pm

    DoesNotExist is documented here:

    The DoesNotExist exception inherits
    from
    django.core.exceptions.ObjectDoesNotExist,
    so you can target multiple
    DoesNotExist exceptions.

    so you can perfectly well use except ObjectDoesNotExist: and catch all the model-specific DoesNotExist exceptions that might be raised in the try clause, or use except SomeSpecificModel.DoesNotExist: when you want to be more specific.

    If you’re looking for the specific spot in Django’s source code where this attribute is added to model classes, see here, lines 34-37:

    # Create the class.
    new_class = type.__new__(cls, name, bases, {'__module__': attrs.pop('__module__')})
    new_class.add_to_class('_meta', Options(attrs.pop('Meta', None)))
    new_class.add_to_class('DoesNotExist', types.ClassType('DoesNotExist', (ObjectDoesNotExist,), {}))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I see them all the time and always ignore them. Can someone explain to
I see this all the time in Ruby: require File.dirname(__FILE__) + /../../config/environment What does
I see this all the time: object literals declared such that some keys are
I work on Linux all the time and I'm clueless about Windows, not even
This doesn't happen all the time. A bug is not a bug if cannot
I have few simple django-based sites and I their number increasing all the time.
My memory usage increases over time and restarting Django is not kind to users.
Background: I'm starting to use Django for the first time, which is also my
I am building a Django application that will be using UTC for all time
In informatics theory I hear and read about high-level and low-level languages all time.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.