如何检查我发送给 django 的令牌是否存在? jango rest 框架有内置函数来检查这个吗?
目前我有登录名,每次用户登录时我都会创建令牌
c86177ae21c1c0b83a5c0354e742334ef2f376f3
答案 0 :(得分:3)
是的 - Django 有一个内置的方法来检测查询集是否不为空。使用文档中描述的 .exists()
方法:
https://docs.djangoproject.com/en/3.1/ref/models/querysets/
if Authtoken.objects.filter(pk="c86177ae21c1c0b83a5c0354e742334ef2f376f3").exists():
# returns True if the queryset is NOT empty.
希望这有帮助;)