[Django]-Django force_login not logging the Django Client in?

4๐Ÿ‘

I was having a similar issue in my tests where the user was getting redirected to the login page even though I was using force_login.

In fact, the user was logged in, but was missing a permission required to view the page.

When I added the required permission (as follows), I was able to post successfully to the page without being redirected.

    perm = Permission.objects.get(codename='can_approve_requests')
    user.user_permissions.add(perm)

More info on permission here Django Permissions and Authorization

I hope this helps.

๐Ÿ‘คshawn

Leave a comment