title: Django Login Form / Invalid User
body: <p>I am learning Django and started building a simple login form. My view is working(redirecting to '/person/) when providing authenticated Username/Password. But it's throwing an ERROR ''AnonymousUser' object has no attribute '_meta'" when providing invalid credentials. Below is my view.</p>
  
  <pre><code>#views.py
  def userlogin(request):
      username = request.POST.get('username')
      password = request.POST.get('password')
      user = authenticate(username=username, password=password)
      auth_login(request, user)
      if user is not None:
          if user.is_active:
              print("User is valid, active and authenticated")
              return HttpResponseRedirect('/person')
          else:
              print("The password is valid, but the account has been disabled!")
              # return HttpResponseRedirect('/person/login')
              return render(request, 'login.html')
      else:
          print("The username and password were incorrect.")
          return HttpResponseRedirect('/person/login')
  
      return render(request, 'login.html')
  </code></pre>