Skip to content

DRF Permission

冒菜略寡味 edited this page May 9, 2018 · 2 revisions

DRF权限设置

1. DRF权限配置 permission

  • 配置视图:apps/bills/views
from rest_framework.permissions import IsAuthenticated
class BillsViewSet(viewsets.ModelViewSet):
    ...
    permission_classes = (IsAuthenticated,)
  • 配置视图:apps/categorys/views
from rest_framework.permissions import IsAuthenticated
class CategorysViewSet(viewsets.ModelViewSet):
    ...
    permission_classes = (IsAuthenticated,)
  • 配置项目路由:accountbook/urls.py
urlpatterns = [
    ...
    path('api-auth/', include('rest_framework.urls'))
]

2. 创建超级用户

设置权限后,需要通过超级用户登录后才能访问相关接口,所以这里需要创建超级用户;

python manage.py createsuperuser

昨日擔當 昨日敢想

昨日轉眼 就跌撞

夏時夢長 秋時晝短

清冽途上 不遠望

Clone this wiki locally