1.1 參考七牛雲SDK
# pythonSDK
https://developer.qiniu.com/kodo/sdk/1242/python
1.2 在 oauth/urls.py 中添加生成七牛雲token的路由
urlpatterns = [
path('qntoken/', views.QNYTokenView.as_view()), # /oauth/qntoken/
]
1.3 在 oauth/views.py 中添加視圖函數

'''獲取上傳token''' class QNYTokenView(APIView): def get(self,request): from qiniu import Auth, put_file, etag import qiniu.config # 需要填寫你的 Access Key 和 Secret Key access_key = "PwyTqrclbus4ntRct1o8G2V-qkR1rI7hbd_5Gx29" secret_key = "IuvSm1vJh2YUiYWFwV-kGmHAJF9R9iGuH2Q1ifea" # 構建鑒權對象 q = Auth(access_key, secret_key) # 要上傳的空間 bucket_name = 'syl-images' # 生成上傳 Token,可以指定過期時間等 token = q.upload_token(bucket_name, expires=3600) return Response({'code': 0, 'msg': '獲取', 'data': {'uptoken': token}})
1.4 測試獲取七牛雲token接口
http://192.168.56.100:8888/oauth/qntoken/