Django中使用djangorestframework产生Token

修改settings.py:

  INSTALLED_APPS添加rest_framework

产生Token

  from rest_framework.authtoken.models import Token

  Token.objects.update_or_create(user=request.user)

获取Token

  from rest_framework.authtoken.models import Token

  Token.objects.get(user=request.user)

 

posted @ 2019-09-03 15:31  BRYANT_2019  阅读(649)  评论(0编辑  收藏  举报