如果不允许用户查看实例的内容,则抛出PermissionDenied异常,而不是将其转发到404.html模板,而是出现错误。
DetailView:
class OccurrenceDetail(OccurrenceModel, BaseDetailViewWithLogin):
permission_required = ('occurrences.see_occurrence')
def get_object(self, queryset=None):
perm = self.request.user.has_perm(self.permission_required)
obj = super(OccurrenceDetail, self).get_object(queryset=queryset)
if not perm:
raise PermissionDenied()
return obj
网址:
handler403 = 'apps_core.core.views.error_403'
观看次数:
def error_403(request):
data = {}
return render(request,'errors/403.html', data)
答案 0 :(得分:5)
403
error view需要第二个参数,这是引发的异常。
要解决此问题,您可以将代码更改为:
def error_403(request, exception):
...
或更一般的
def error_403(request, *args, **kwargs):
...