我正试图通过遵循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')
任何帮助都是有益的
你需要做一个post请求
相关问题 更多 >
编程相关推荐