title: Trying to verify a user with Django email confirmation, however some user's are getting this error when they try to confirm their email
body: <p>I asked a variant of this question before, but realized I was very unclear. This is my attempt at doing a better job of explaining the issue.  </p>
  
  <p>I send a link to a user's email to confirm sign-up after they have registered for the site. However, a small proportion of users are getting the following error when they try to confirm their email. </p>
  
  <p>Error:</p>
  
  <pre><code>TypeError/activate/{uidb64}/{token}/
  error
  'AnonymousUser' object is not iterable
  </code></pre>
  
  <p>I think the problem is that the activate function is not recognizing them. However, not sure how to make this activation link work if I send them back to the login page. Any ideas?</p>
  
  <p>Do I need to add something like 'if not user.is_authenticated:' then send redirect to login? But, how do I come back to activate function? Login is general in my app to all situations.</p>
  
  <p>Activate code:</p>
  
  <pre><code>try:
      uid = force_text(urlsafe_base64_decode(uidb64))
      user = User.objects.get(pk=uid)
  except(TypeError, ValueError, OverflowError, User.DoesNotExist):
      user = None
  if user is not None and account_activation_token.check_token(user, token):
      .... do something
  else:
      return HttpResponse('Activation link is invalid!')
  </code></pre>
  
  <p>Here is where I create the email:</p>
  
  <pre><code>def activation_email(request):
      if request.user.is_authenticated:
          user=request.user
          message = render_to_string('email.html', {
                  'user':user,
                  'token':account_activation_token.make_token(user),
                  'uid':urlsafe_base64_encode(force_bytes(user.pk)),
          })
          ....send mail
      else:
          return redirect('somewhere_else')
  </code></pre>
  
  <p>EDIT>: It's failing when I try to update my model with the email verification info:</p>
  
  <pre><code>if user is not None and account_activation_token.check_token(user, token):
        object, created = User_Profile.objects.get_or_create(
              user=request.user,
              ## This is where it fails
              email_validated=True,
          )
  </code></pre>