gpt4 book ai didi

python - django 错误(外部 IP)

转载 作者:太空宇宙 更新时间:2023-11-03 13:05:01 25 4
gpt4 key购买 nike

每次输入不存在的地址时,我都会收到通知。

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.

如何解决

最佳答案

修改您的查询以使用 get_object_or_404 , 或者 catch YourModel.DoesNotExist (第 3 段)进行查找时出现异常,并引发 Http404异常(exception)。当您没有捕捉到 DoesNotExist 异常时, View 会引发 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

关于python - django 错误(外部 IP),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6080024/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com