N
N
Nikita Tonkoshkurov2020-06-16 13:47:07
Django
Nikita Tonkoshkurov, 2020-06-16 13:47:07

Problem with django rest framework and knox?

I'm trying to write a rest-api for authentication through knox,
but when I try to post a request to

`auth/login/`
issues
`TypeError at /authentication/login/
'str' object is not callable `


my views.py

class LoginAPI(LoginView):
    permission_classes = (permissions.AllowAny)

    def post(self, request, format=None):
        serializer = LoginSerializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        user = serializer.validated_data['user']
        login(requests, user)
        return super().post(request, format=None)


my urls.py
urlpatterns = [
    path('login/', LoginAPI.as_view()),
    path('validate_phone/', ValidatePhone.as_view()),
    path('validate_otp/', ValidateOTP.as_view()),
    path('register/', Register.as_view()),]


my setting.py

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': {'knox.auth.TokenAuthentication', }
       }

     REST_KNOX = {
    'USER_SERIALIZER': 'users.serializers.UserSerializer',
    'TOKEN_TTL': timedelta(hours=24 * 7)
      }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Tikhonov, 2020-06-16
@tumbler

login(requests, user) is a typo.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question