Django error (EXTERNAL IP)

I get notifications every time you enter an address that does not exist.

Traceback (last last call): File "/home/user/opt/local/django/core/handlers/base.py", line 100, in get_response File "/web/blog/views.py", line 33, in message File /home/user/local/django/db/models/manager.py ", line 132, to get File" /home/user/opt/local/django/db/models/query.py ", line 347 , in DoNotExist: a match request does not exist.

how to solve it

+3
source share
4 answers

, get_object_or_404, YourModel.DoesNotExist ( ), , Http404. DoesNotExist, 500. ADMINS, settings.py.

:

from django.shortcuts import get_object_or_404

post_id = 1
post = get_object_or_404(Post, id=post_id)

# or catch the exception and do something with it

from django.http import Http404
try:
    post = Post.objects.get(id=post_id)
except Post.DoesNotExist:
    # id doesnt exist... do extra things here
    raise Http404
+6

- , get . 404 , sdolan , . , , - , get try catch. :

try:
    post = Post.object.get(pk=id)
except Post.DoesNotExist:
    post = None
    # Probably use some sensible defaults, or do something else
+1

use get_object_or_404 in the request, see the documentation for more information.

http://docs.djangoproject.com/en/1.3/topics/http/shortcuts/#get-object-or-404

+1
source

I assume that the main problem is your view file, where you are working with the HTTP response request object. Check that all settings are accurate in settings.py, also use try except block to more accurately find the error.

0
source

All Articles