I'm studying janggu. Everyone in the lecture and on the internet Teach them to stop DoesNotExist using 'get_object_or_404'.
Both are errors, but I wonder why you change 500 errors (server errors) to 404 errors (client errors).
Are you trying to tell me this?
Looking at Wiki, 404 is "This is an HTTP standard response code that indicates that the client can communicate with the server, but the server cannot find the request." If so, is it impossible to communicate with the server if other errors (200, 300, 500)?
django http
I saw the official document and it said it was philosophy.
Why use the get_object_or_404()
help function instead of automatically catching the
ObjectDoesNotExist
exception in the upper layer, or Http404
instead of using the ObjectDoesNotExist
exception? Because it's a way of connecting the model layer to the view layer. (Limited)
I thought about what it means, but I think it means this. For example, in an NGINX+PHP stack, the most basic treatment when 500 errors are dropped is approximately this.
But just because a DB query failed (at the model layer), it's not good to show this kind of web server-level processing (at the view layer). So a good PHP framework like Laravel handles the error in this way. Let them know there's a problem, and just give them as much information as they need.
Maybe that's why most courses don't drop the ObjectDoesNotExist
error directly. You can send the error to the user, but it probably gives the user an unnecessarily negative, informative experience like, "What do you want me to do?" Rather, I think it means to let them know "This is 404
" and pass by.
If someone else who has used django posts an answer, this article will be deleted.
© 2024 OneMinuteCode. All rights reserved.