1
我目前使用Django-rest-framework-social-oauth2 Django的權威性登錄的api,它的登錄令牌創建端點,這對成功,具有下列數據迴應:如何改變響應格式
{
"access_token": "************",
"token_type": "Bearer",
"expires_in": 36000,
"refresh_token": "************",
"scope": "read write"
}
但我想改變的格式和包裝數據以該格式:
{
"status" : true,
"data" :{
"access_token": "************",
"token_type": "Bearer",
"expires_in": 36000,
"refresh_token": "************",
"scope": "read write"
}
}
我讀Django文檔,並試圖延伸庫視圖,但沒有變化示出了
from rest_framework_social_oauth2.views import TokenView
@api_view(('POST'))
def post(self, request, *args, **kwargs):
# Use the rest framework `.data` to fake the post body of the django request.
request._request.POST = request._request.POST.copy()
for key, value in request.data.items():
request._request.POST[key] = value
url, headers, body, status = self.create_token_response(request._request)
response = Response(data=json.loads(body), status=status)
for k, v in headers.items():
response[k] = v
return response
嗨,不得不將名稱參數值更改爲'authorize',它的工作完美。非常感謝! – user8169843
@ user8169843快樂的幫助隊友:)。 如果需要,您可以通過點擊tic圖標接受答案! –
你值得擁有它。再次感謝! – user8169843