使用JWT:
1、github下载:https://github.com/GetBlimp/django-rest-framework-jwt
2、支持:
Python (2.7, 3.3, 3.4, 3.5, 3.6)
Django (1.8, 1.9, 1.10, 1.11)
Django REST Framework (3.1, 3.2, 3.3, 3.4, 3.5, 3.6)
3、安装: pip install djangorestframework-jwt
4、加入settings中
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_jwt.authentication.JSONWebTokenAuthentication', # JWT 认证
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.BasicAuthentication',
),
}
5、 加入url中
from rest_framework_jwt.views import obtain_jwt_token
#...
urlpatterns = [
'',
# ...
url(r'^api-token-auth/', obtain_jwt_token),
]
结果: