-
Notifications
You must be signed in to change notification settings - Fork 10
DRF Permission
冒菜略寡味 edited this page May 9, 2018
·
2 revisions
- 配置视图:
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'))
]
设置权限后,需要通过超级用户登录后才能访问相关接口,所以这里需要创建超级用户;
python manage.py createsuperuser
... 累到整夜不能睡,夜色哪裡都是美 ...
昨日擔當 昨日敢想
昨日轉眼 就跌撞
夏時夢長 秋時晝短
清冽途上 不遠望