Skip to content

Raise Http404 rather than return HttpResponseNotFound#62

Open
SociologicalReview wants to merge 6 commits intonm-packages:releasefrom
SociologicalReview:raise404_01
Open

Raise Http404 rather than return HttpResponseNotFound#62
SociologicalReview wants to merge 6 commits intonm-packages:releasefrom
SociologicalReview:raise404_01

Conversation

@SociologicalReview
Copy link
Copy Markdown

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).specific

in 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant