Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Token.objects not found

Tags:

python

django

I'm using djangorestframework in django==2.0 with python 3.7

I put an event like this

@receiver(post_save, sender=settings.AUTH_USER_MODEL)
def create_auth_token(sender, instance=None, created=False, **kwargs):
    if created:
        from rest_framework.authtoken.models import Token
        Token.objects.create(user=instance)

when I tried to create a user the compiler giving an error:

Exception Value:    
type object 'Token' has no attribute 'objects'
like image 615
Muhammadjon Avatar asked Aug 22 '26 08:08

Muhammadjon


1 Answers

Try to do the following

>>> from rest_framework.authtoken.models import Token
>>> Token.objects.all()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: type object 'Token' has no attribute 'objects'

If the above error occurs, That's because you didn't add the auth token in the settings' INSTALLED_APPS. if it's not the in the INSTALLED_APPS, it's abstract and doesn't have the default manager (objects).

like image 107
Ajay Singh Avatar answered Aug 23 '26 23:08

Ajay Singh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!