我有以下功能(只顯示爲完整起見進口):DRF - 獲取不允許
from django.utils import timezone
from rest_framework import status
from rest_framework.response import Response
from rest_framework.authtoken.models import Token
from rest_framework.authtoken.views import ObtainAuthToken
class RefreshAuthToken(ObtainAuthToken):
def post(self, request):
key = request.query_params.get('auth_token').strip()
try:
token = self.model.objects.get(key=key)
token.delete()
token = Token.objects.create(user=serializer.object['user'])
token.created = datetime.datetime.utcnow().replace(tzinfo=utc)
token.save()
return Response({'token': token.key})
except self.model.DoesNotExist:
return Response("Error", status=status.HTTP_400_BAD_REQUEST)
當我訪問的URL以/ AUTH_TOKEN = 619f853ac32e171facb3068c990c6eded81a59c9,我得到一個錯誤:
?{"detail":"Method \"GET\" not allowed."}
我該如何解決這個問題?
謝謝
你需要設置已存在的令牌密鑰,而不是blablabla – UserGraund
我有一個現有的密鑰。 – TruniTr
這個關鍵值是blablabla? – UserGraund