https://github.com/sonhm3029/django_note
This is django settings note and self experience gain
https://github.com/sonhm3029/django_note
Last synced: 3 months ago
JSON representation
This is django settings note and self experience gain
- Host: GitHub
- URL: https://github.com/sonhm3029/django_note
- Owner: sonhm3029
- Created: 2022-11-15T02:44:49.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-12-14T10:31:03.000Z (over 2 years ago)
- Last Synced: 2025-01-17T01:25:17.890Z (4 months ago)
- Language: JavaScript
- Size: 1000 Bytes
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Django basic setting
## 1. Authentication project-level permissions
```Python
# project/settings.py
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.AllowAny',
]
}
```Với
- `AllowAny`: Tất cả các user, không có auth vẫn có full quyền với API
- `IsAuthenticated`: Chỉ có authenticated, registered user mới có quyền truy cập
- `IsAdminUser`: Chỉ admins/superusers có quyền truy cập API
- `IsAuthenticatedOrReadOnly`: users không có auth thì chỉ có thể view api, chỉ có users có auth thì mới có thể ghi, sửa, xóa## 2. Base class for rest_framework views
- `APIView`: Sử dụng để customize các api request
- `viewsets.ModelViewSet`: Sử dụng khi alloww tất cả CRUD api
- `generics.*subclasses`: Sử dụng khi chỉ allow một số api method## 3. Deployment