I am trying to implement an API which returns a token upon a post request with valid email and password. I am using the rest framework for token authentication. To do this, I customized the ObtainAuthToken view from rest_framework to use my own serializer which works with an email instead of a username. The endpoint works flawlessly but I don't get the browsable API when I visit the endpoint in my browser. I just get a blank page with the following line:

{"detail":"Method \"GET\" not allowed."}

views.py

from rest_framework.authtoken.views import ObtainAuthToken
from .serializers import UserTokenSerializer


class CreateUserToken(ObtainAuthToken):
    serializer_class = UserTokenSerializer

What is wrong with my view? I think I'm missing something.

1

There are 1 answers

0
Solomon Botchway On

I had to set renderer_classes like so:

from .serializers import UserTokenSerializer

from rest_framework.authtoken.views import ObtainAuthToken
from rest_framework.settings import api_settings


class CreateUserToken(ObtainAuthToken):
    serializer_class = UserTokenSerializer

    # To get the browsable API;
    renderer_classes = api_settings.DEFAULT_RENDERER_CLASSES