TokenAuthentication
此认证方案使用简单的基于令牌的 HTTP 认证方案。令牌身份验证适用于 client-server 架构,例如本机桌面和移动客户端。
要使用 TokenAuthentication 方案,您需要将认证类配置为包含 TokenAuthentication ,并在主settings中
的 INSTALLED_APPS 设置中加入 rest_framework.authtoken
:
INSTALLED_APPS = (
...
'rest_framework.authtoken'
)

注意: 确保在更改设置后运行
make migratins
和make migrate
,为rest_framework.authtoken 应用程序提供 Django 数据库迁移
。
主url中:

api的drf_views中:

生成令牌
Ipython中获取token:



=========================================================
Postman中获取token:



数据库中:

网友评论