Home > Back-end >  File "C:\django\2proj\authentication\utils.py", line 2, in <module> from six imp
File "C:\django\2proj\authentication\utils.py", line 2, in <module> from six imp

Time:02-23

Am trying to import module six in my utils.py but its not working

    from django.contrib.auth.tokens import PasswordResetTokenGenerator
    from six import text_type
    from django_six import text_type



class AppTokenGenerator(PasswordResetTokenGenerator): 

  def _make_hash_value(self, user, timestamp):
        return (text_type(user.is_active)   text_type(user.pk)   text_type(timestamp))

account_activation_token = AppTokenGenerator()

but i get this error " File "C:\django\2proj\authentication\utils.py", line 2, in from six import text_type ModuleNotFoundError: No module named 'six'"

Am using django 4.0.2

CodePudding user response:

You don't need six these days; your code is equivalent to

from django.contrib.auth.tokens import PasswordResetTokenGenerator


class AppTokenGenerator(PasswordResetTokenGenerator):
    def _make_hash_value(self, user, timestamp):
        return f"{user.is_active}{user.pk}{timestamp}"


account_activation_token = AppTokenGenerator()
  • Related