Questions tagged «class-based-views»

13
如何在基于Django类的视图上使用Permission_required装饰器
我在理解新CBV的工作方式时遇到了一些麻烦。我的问题是,我需要在所有视图中登录,并且在某些视图中需要特定的权限。在基于函数的视图中,我使用@permission_required()和视图中的login_required属性来执行此操作,但是我不知道如何在新视图上执行此操作。django文档中是否有某些部分对此进行了解释?我什么都没找到 我的代码有什么问题? 我尝试使用@method_decorator,但它回答“ / spaces / prueba / _wrapped_view()处的TypeError至少接受1个参数(给定0) ” 这是代码(GPL): from django.utils.decorators import method_decorator from django.contrib.auth.decorators import login_required, permission_required class ViewSpaceIndex(DetailView): """ Show the index page of a space. Get various extra contexts to get the information for that space. The get_object method searches in the user 'spaces' field …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.