[英]"detail": "Method \"GET\" not allowed." in TokenAuthentication Django rest framework
I am trying to build a token-based authentication system by followinghttps://www.django-rest-framework.org/api-guide/authentication/ .我正在尝试通过遵循https://www.django-rest-framework.org/api-guide/authentication/来构建基于令牌的身份验证系统。
But on sending a request, I am getting an error msg as a response:但是在发送请求时,我收到一个错误消息作为响应:
{ "detail": "Method "GET" not allowed."
{“详细信息”:“不允许使用方法“GET”。” }
}
Here is what I have tried so far:这是我迄今为止尝试过的:
urls.py网址.py
urlpatterns = [
path('api-token-auth/', views.obtain_auth_token),
]
models.py模型.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视图.py
def index(request):
return render(request,'index.html')
Any help would be beneficial.任何帮助都是有益的。
你需要做一个post请求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.