Skip to content Skip to sidebar Skip to footer

Django: Handler403 Doesn't Work, But 404 Does

Here is content of MyProj/urls.py: from django.contrib import admin from django.urls import path, include urlpatterns = [ path('admin/', admin.site.urls), path('', include

Solution 1:

My guess is that your views returns a django.http.HttpResponseForbidden instead of raising a django.core.exceptions.PermissionDenied exception.

Only the PermissionDenied exception gets handled by handler403, a HttpResponseForbidden is returned as is.


Solution 2:

If that's really your handler403 file (aka. handler403.py), you'll probably want

handler403 = 'general.views.handler403.handler403'

(so a dotted path to the actual callable).


Solution 3:

handler403 should point to a view

Try something like this:

from general.views.handler403 import handler403

handler403 = handler403

Post a Comment for "Django: Handler403 Doesn't Work, But 404 Does"