“详细信息”:“不允许使用方法\”GET \“。在TokenAuthentication Django rest框架中

2024-04-27 03:25:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图通过遵循https://www.django-rest-framework.org/api-guide/authentication/构建一个基于令牌的身份验证系统

但在发送请求时,我收到一条错误消息作为响应:

{ "detail": "Method "GET" not allowed." }

以下是我迄今为止所尝试的:

url.py

urlpatterns = [
    path('api-token-auth/', views.obtain_auth_token),
]

models.py

@receiver(post_save, sender=settings.AUTH_USER_MODEL)
def create_auth_token(sender, instance=None, created=False, **kwargs):
    if created:
        Token.objects.create(user=instance)

views.py

def index(request):

    return render(request,'index.html')

任何帮助都是有益的


Tags: instancepyhttpstokenauthapiindexrequest