1👍
In Django 1.9+, you can use the UserPassesTestMixin
instead of a decorator, and set raise_exception
to True
.
Since you are using Django 1.4, which is insecure and obsolete, you won’t be able to do this. There isn’t an option to make user_passes_test
raise PermissionDenied
rather than redirect. You could either try to detect the redirect in your JavaScript, or look at the user_passes_test
source code and implement something similar that returns the response you want.
Source:stackexchange.com