I'm trying to implement my own serializer and view to handle Token based authentication with email instead of username. In copying the ObtainAuthToken view, an error is returned about the Token
object not having the objects
attribute.
mkdir restframework
cd restframework/
virtualenv env
source env/bin/activate
pip install django
pip install djangorestframework
django-admin startproject tutorial
cd tutorial
python manage.py shell
## Expected behavior
Token class can query objects
## Actual behavior
python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 03:03:55)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
from rest_framework.authtoken.models import Token
Token.objects.all()
Traceback (most recent call last):
File "", line 1, in
AttributeError: type object 'Token' has no attribute 'objects'
```
This class (being a django model) should be able to query using the objects
attribute, should it not?
That's because you didn't add the auth token in the settings' INSTALLED_APPS
Edit: if it's not the in the INSTALLED_APPS
, it's abstract and doesn't have the default manager (objects
).
@xordoquy Thank you!
Add 'rest_framework.authtoken'
to INSTALLED_APPS list in settings.py
Most helpful comment
That's because you didn't add the auth token in the settings'
INSTALLED_APPS
Edit: if it's not the in the
INSTALLED_APPS
, it's abstract and doesn't have the default manager (objects
).