title: Django PasswordResetTokenGenerator, check_token(user, token) returns False on Production, Locally Works Fine
body: <p><strong>Problem:</strong> I'm using Django built-in class "PasswordResetTokenGenerator" to generate a token, For user account activation link, Which is sent to the user via email after submitting RegistrationForm.(I use Celery and RabbitMQ for Task execution and message queuing)</p>
  
  <p><strong>views.py (RegistrationView)</strong></p>
  
  <pre><code>class MyUserCreationView(FormView):
      template_name = 'accounts/auth/register.html'
      form_class = MyUserCreationForm
  
      def form_valid(self, form):
          user = form.save(commit=False)
          user.is_active = False
          email = user.email
          user.save()
          current_site = str(get_current_site(self.request))
          confirm_mail.apply_async((user.username, current_site), countdown=5)
          return render(self.request, 'accounts/auth/register.html', {'email': email})
  </code></pre>
  
  <p><strong>tokens.py</strong></p>
  
  <pre><code>from django.contrib.auth.tokens import PasswordResetTokenGenerator
  from django.utils import six
  
  class TokenGenerator(PasswordResetTokenGenerator):
      def _make_hash_value(self, user, timestamp):
          return (
              six.text_type(user.pk) + six.text_type(timestamp)+ six.text_type(user.is_active)
  
          )
  
  account_activation_token = TokenGenerator()
  </code></pre>
  
  <p><strong>tasks.py (Celery Task)</strong> Sends Email to the user</p>
  
  <pre><code>from django.core.mail import send_mail
  from django.contrib.auth.models import User
  from django.template.loader import render_to_string
  from django.utils.encoding import force_bytes
  from django.utils.http import urlsafe_base64_encode
  from django.shortcuts import get_object_or_404
  
  from celery import task
  
  from ecommerce.settings.base import EMAIL_HOST_USER
  from account.tokens import  account_activation_token
  
  @task
  def confirm_mail(user_name, current_site):
  
      user_obj = get_object_or_404(User,username=user_name)
      token=account_activation_token.make_token(user_obj)
  
      subject = 'Activate your MissIndia account.'
      message = render_to_string(
          'email/acc_activate_email.html',
          {
              'user': user_obj,
              'domain': current_site,
              'uid': urlsafe_base64_encode(force_bytes(user_obj.pk)).decode(),
              'token': token,
          }
      )
  
      mail_sent = send_mail(subject, message, EMAIL_HOST_USER, [
                          user_obj.email], fail_silently=False)
  
      return mail_sent
  </code></pre>
  
  <p><strong>urls.py</strong></p>
  
  <pre><code>from django.urls import path, re_path
  from . import views
  app_name = 'accounts'
  urlpatterns = [
      re_path('confirm-email/(?P&lt;uidb64&gt;[0-9A-Za-z_\-]+)/(?P&lt;token&gt;[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', views.activate, name='activate'),
  ]
  </code></pre>
  
  <p><strong>views.py</strong> (Activate account)</p>
  
  <pre><code>def activate(request, uidb64, token):
      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):
          user.is_active = True
          user.save()
          # login(request, user)
          # return redirect('home')
          return HttpResponse('Thank you for your email confirmation. Now you can login your account.')
      else:
          return HttpResponse('Activation link is invalid!')
  </code></pre>
  
  <blockquote>
    <p><strong>NOTE:</strong> By Doing SSH into my EC2 instance, If i execute confirm_mail() function in tasks.py using Django shell commands It sends valid activation link.</p>
  </blockquote>