Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 403 page #114

Closed
wants to merge 2 commits into from
Closed

Add 403 page #114

wants to merge 2 commits into from

Conversation

elmaxe
Copy link
Member

@elmaxe elmaxe commented Nov 9, 2021

This PR renders 403 pages on all 403 instances. This PR also renders the existing 404 page on 404 instances, which wasn't always the case previously.

Fixes: #110

@elmaxe elmaxe requested a review from oskstr November 9, 2021 10:04
@@ -75,7 +77,9 @@ def attest_invoice_part(request, pk):
try:
invoice_part = InvoicePart.objects.get(pk=int(pk))
except ObjectDoesNotExist:
raise Http404("Fakturadelen finns inte")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are basically replicating the default behavior of django here, but also removing the debug functionality on errors.

How it works is if DEBUG=False (as it is in production) when this gets called:

raise Http404("Fakuradelen finns inte")

django would run this function:

defaults.page_not_found(request, exception, template_name='404.html')

which calls the template 404.html with the variables request_path and exception (in this case "Fakturadelen finns inte")

so it would render something like this with your updated template:
cashflow-403-2

Similar things work for other errors but have different variables available by default (can be overridden):

  • 400.html (nothing passed to template by default)
  • 403.html (exception passed to template)
  • 500.html (nothing passed to template by default)

Here are some more resources about it: Error Views.

But as it is written it would remove stack traces when you have DEBUG=True in development.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth mentioning is that it looks like when a 404 is triggered by not being able to resolve the path, it still has an exception but it is called Resolver404. So this is how that would look:
cashflow-403-3

@elmaxe elmaxe closed this Apr 15, 2022
@foodelevator foodelevator deleted the 403-page branch September 19, 2023 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Render 403 page when trying to do something you aren't allowed to
2 participants