Raise Http404 rather than return HttpResponseNotFound #62
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The Django docs recommend that it is better to raise the Http404 error rather than return HttpResponseNotFound so as to provide a more consistent 404 page across a website:
https://docs.djangoproject.com/en/5.2/topics/http/views/#the-http404-exception
This update replaces HttpResponseNotFound with Http404 and provides additional error handling around the parsing the of "id" parameter so as to provide a smoother experience for public visitors to a site. Additional information is given with these errors for debugging purposes.
The two lines retrieving "specific_class" and then the page itself have been replaced with a single line:
page = Page.objects.get(id=page_id).specificin keeping with more common Wagtail practice.
The call to update "qr_code_usage" has been separated out from returning the page so as to allow a page to be returned whenever there is a valid URL, even if that specific page no longer integrates the QR code usage count.
The redirect to the page.url ends the view function to allow any other error handling to be passed onto the specific page view itself.