【发布时间】:2021-06-30 22:43:01
【问题描述】:
如何检查我发送给 django 的令牌是否存在? jango rest 框架有内置函数来检查这个吗?
目前我已经登录,每次用户登录时我都会创建令牌
c86177ae21c1c0b83a5c0354e742334ef2f376f3
【问题讨论】:
标签: django django-rest-framework django-rest-auth
如何检查我发送给 django 的令牌是否存在? jango rest 框架有内置函数来检查这个吗?
目前我已经登录,每次用户登录时我都会创建令牌
c86177ae21c1c0b83a5c0354e742334ef2f376f3
【问题讨论】:
标签: django django-rest-framework django-rest-auth
是的 - 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.
希望这会有所帮助;)
【讨论】: