'AnonymousUser' object has no attribute 'is_admin'

后端 未结 2 589
旧巷少年郎
旧巷少年郎 2021-01-28 22:42

I am using Django 2.2 and Python 3.6.

I deployed a Django REST server using AWS EB, but I get the following error.

It works fine on the local side, but an error oc

2条回答
  •  广开言路
    2021-01-28 22:59

    The first problem is that AnonymousUser does not have an is_admin property in django. You can maybe check is_superuser or check if your user is authenticated before calling is_admin on it. See How to check if a user is logged in (how to properly use user.is_authenticated)? for that.

    About the difference between local and distant, I would guess that you're logged in on your local app but not on your distant app. This is why AnonymousUser gets returned by request.user on your distant app.

提交回复
热议问题