0

I am trying to get an auth token for the client (OrderClient.py). This keeps failing with Forbidden (CSRF cookie not set.): /auth. Here is my views

from rest_framework.decorators import api_view,permission_classes,authentication_classes
from rest_framework.response import Response
from .serializers import OrderSerial
from rest_framework.authentication import SessionAuthentication, TokenAuthentication
from rest_framework.permissions import IsAuthenticated

@api_view(['POST'])
@authentication_classes([SessionAuthentication, TokenAuthentication])
@permission_classes([IsAuthenticated])
def make_order(request,*args,**kwargs):
    user1=request.user

    serializer = OrderSerial(user=user1)
    print(serializer.is_valid())
    data={'abc':'cde'}
    return Response(data=data)

Here is my urls.py

from django.urls import path
from Products.views import home_view,Phone_input_view,Phone_list_view,Phone_edit_view
from Products.api.views import make_order
from rest_framework.authtoken.views import obtain_auth_token

urlpatterns = [
    path('',home_view),
    path('auth/', obtain_auth_token),
    path('createPhone/',Phone_input_view),
    path('viewPhoneList/',Phone_list_view),
    path('edit/<int:id>',Phone_edit_view),
    path('order/', make_order)
]

I have added the 'rest_framework.authtoken' to installed apps in settings.

I was expecting to retrieve the token and successfully sign in

Here is the link to my github repository: https://github.com/henselwilson/TrialProject

0 Answers0