Django rest framework: Obtain auth token using email instead username

前端 未结 4 1750
有刺的猬
有刺的猬 2020-12-24 08:39

I\'m working on a project to enable the django rest framework authentication for mobile devices. I\'m using the default token authentication for get the user token from a po

4条回答
  •  無奈伤痛
    2020-12-24 09:27

    There is a cleaner way to get the user token.

    simply run manage.py shell

    and then

    from rest_framework.authtoken.models import Token
    from django.contrib.auth.models import User
    u = User.objects.get(username='admin')
    token = Token.objects.create(user=u)
    print token.key
    

提交回复
热议问题