使用 CURL

如果针对此端点运行卷曲

curl http://localhost:8000/auth/    
op : {"detail": "Authentication credentials were not provided."}%

将返回 401 错误 UNAUTHORIZED

但是如果我们之前得到一个令牌:

curl -X POST -d "user=Pepe&password=aaaa"  http://localhost:8000/
{"token": "f7d6d027025c828b65cee5d38240aec60dffa150", "detail": "POST answer"}%

然后我们将该标记放入请求的标题中,如下所示:

curl http://localhost:8000/auth/ -H 'Authorization: Token f7d6d027025c828b65cee5d38240aec60dffa150'

op: {"detail": "I suppose you are authenticated"}%