空白页面和视图上的代码403

时间:2015-02-12 15:06:34

标签: python django permissions http-status-code-403 django-guardian

我想为Employee组中的用户添加权限,以便能够查看视图,但不添加。当我去装饰器查看时,我得到一个空白页面和代码403。 我用django-guardian。

MODEL

class MyModel(models.Model):
    name = models.CharField(max_length=255, blank=True, null=True, help_text=_('Please enter name'))
    date_from = models.DateField(help_text=_('Please specify start date'))
    date_to = models.DateField(help_text=_('Please specify end date'))

    class Meta:
        verbose_name = _('MyModel')
        verbose_name_plural = _('MyModels')
        permissions = (
            ('can_view', _('Can view')),
            ('can_add', _('Can add')),
        )

    def __unicode__(self):
        return self.free_day_type

查看

class Add(CreateView):
    template_name = "myapp/add.html"
    model = MyModel
    form_class = MyModelInputForm
    success_url = reverse_lazy('myapp:add')

    @method_decorator(permission_required_or_403('myapp.can_view'))
    @method_decorator(permission_required_or_403('myapp.can_add_holidays'))
    def dispatch(self, *args, **kwargs):
        return super(Add, self).dispatch(*args, **kwargs)

管理

from django.contrib import admin
from .models import MyModel
from guardian.admin import GuardedModelAdmin


class MyModelAdmin(GuardedModelAdmin):
    pass

admin.site.register(MyModel, MyModelAdmin)

0 个答案:

没有答案