I am receiving notifications every time, when enter an address that does not exist.
Traceback (most recent call last):
File “/home/user/opt/local/django/core/handlers/base.py”, line 100, in get_response
File “/web/blog/views.py”, line 33, in post
File “/home/user/local/django/db/models/manager.py”, line 132, in get
File “/home/user/opt/local/django/db/models/query.py”, line 347, in get
DoesNotExist: Post matching query does not exist.
how to solve it
Modify your query to use
get_object_or_404, or catch theYourModel.DoesNotExist(3rd paragraph) exception when you’re doing the lookup, and raise aHttp404exception. When you don’t catch theDoesNotExistexception the view raises a 500 error. As a side effect, this sends an exception email to the theADMINSdefined itsettings.py.Example of both cases: