简体   繁体   中英

How to get Token from Django Rest Framework using postman

I try to get Token like in Django Rest Framework Documentation

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

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

But it always return to me

  {
  "username": [
    "This field is required."
  ],
  "password": [
    "This field is required."
  ]
}

邮递员窗口

You should add the informations in body request (choice this option). for example:

{"username": "Werton", "password": "xpto"}

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM