[Django]-Django Rest framework authtoken 'module' object has no attribute 'views'

10👍

The reason it doesn’t work – authtoken is a package – when you import it, it does not contain what you want –

>>> from rest_framework import authtoken
>>> dir(authtoken)
['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__']

You can see that authtoken does not contain anything useful. However the view you are interested in is actually inside the views module.

So we can first change the import to:

from rest_framework.authtoken import views as authviews

Then use it in the urlconf:

url(r'^api-token-auth/', authviews.obtain_auth_token),
👤masnun

2👍

I was facing same error, but I realized that below thing.

You need to add rest_framework.authtoken to your INSTALLED_APPS,
And don’t forget to python manage.py migrate

👤Omkar

Leave a comment