I am trying custom authentication with django, I wrote a class and filled it with the methods authenticate and get\_user, I also added this authentication to the AUTHENTICATION\_BACKENDS in settings.py file.

I have called authenticate method and followed it up with login in my view.

Everything seems to work fine, 

1. is\_authenticated returns true for the user after login,
2. user.backends set to my custom backend.
3. sessionid cookie is getting set in my browser

But the subsequent requests have request.user as anonymous, unable to figure out the reason, require your help. Sharing the code below, I am just trying it to learn custom authentication.

views.py

```
 def home(request):
   if not request.user.is_authenticated():
    user=authenticate(username=None,passwd=None,request=request)
    if not user:
        return HttpResponse("Login Failed")
    else:
        login(request,user)
        return HttpResponse("Logged in Successfully")

```

cusauth.py

```
class CustomloginBackend:

  def authenticate(self,username=None,passwd=None,request=None):
    return self.get_user("praveen.madhavan")

  def get_user(self,username):
    try:
        return User.objects.get(username=username)
    except Exception as e:
        return False

```

What could be the problem ?

Thanks

Praveen.M