'AnonymousUser' object is not iterable

后端 未结 2 1537
暖寄归人
暖寄归人 2021-02-19 20:29
if not request.user.is_authenticated:
    return None

try:
    return ClientProfile.objects.get(user=request.user)
except ClientProfile.DoesNotExist:
    return None
         


        
2条回答
  •  北恋
    北恋 (楼主)
    2021-02-19 20:55

    This error might arise if you are trying to logging in as a guest user. In my project i m trying to provide membership on the basis of free,enterprise and professional and i got the same error.

    so replace

    return ClientProfile.objects.get(user=request.user) with

    return ClientProfile.objects.filter().first()

提交回复
热议问题