Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Tutorial - turning on PAGINATE_BY breaks custom permissions #2205

Closed
Labels
Milestone
@detectedstealth

Description

@detectedstealth

When turning on PAGINATE_BY in settingsAdding Pagination

REST_FRAMEWORK= {'PAGINATE_BY':10}

The custom permissionsObject Level Permissions

fromrest_frameworkimportpermissionsclassIsOwnerOrReadOnly(permissions.BasePermission):"""    Custom permission to only allow owners of an object to edit it.    """defhas_object_permission(self,request,view,obj):# Read permissions are allowed to any request,# so we'll always allow GET, HEAD, or OPTIONS requests.ifrequest.methodinpermissions.SAFE_METHODS:returnTrueprint(obj)# Write permissions are only allowed to the owner of the snippet.returnobj.owner==request.user

break when trying to view the list of Snippets with the following error:

AttributeError at /snippets/'Page' object has no attribute 'owner'Request Method: GETRequest URL:    http://127.0.0.1:8000/snippets/Django Version: 1.7.1Exception Type: AttributeErrorException Value:    'Page' object has no attribute 'owner'Exception Location: /Development/Python/django/snippets_tutorial/snippets/permissions.py in has_object_permission, line 14

When disabling the PAGINATE_BY setting you are able to view the Snippets list without any error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp