如何使用postman从Django Rest Framework获取Token

时间:2016-04-14 15:42:31

标签: python django http django-rest-framework postman

我尝试在Django Rest Framework文档中使用Token

isset

在models.py

from rest_framework.authtoken import views
urlpatterns = [
    url(r'^api-token-auth/', views.obtain_auth_token),
]

但它总是回到我身边

@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)

Postman window

1 个答案:

答案 0 :(得分:5)

您应该在正文请求中添加信息(选择此选项)。 例如:

{"用户名":" Werton",  "密码":" xpto"}

enter image description here