I have a doubt when using django.contrib.messages or showing 404 pages in which case I have a Should use the other?
Serial = get_object_or_404 (serial number, serial_number = SE)
or
Try: serial = SerialNumber Objects.get (serial_number = sn) SerialNumber.DoesNotExist except messages.add_message (request, message. Warning, 'not found!')
Thanks in advance!
Assume that you have some URL:
/ article / & Lt; Pk & gt; /
If there is no text with end user call / article / 5 /
and ID 5, then you should not only send a message that you want The search term is not found, but is the appropriate HTTP status code, which is 404. Here you should use the get_object_or_404
.
If you want to display some additional information on page for / article / 4 /
and have an article with ID4, but this is not extra special information, then you The page should display e for the article with id 4, returns the HTTP status code 200, which means that it is okay, and display the message that additional information is not available.
The main difference is that in my opinion the HTTP status code, but I teach others to me, if I am wrong.
Comments
Post a Comment