DEV Community

Ayoola Tosin
Ayoola Tosin

Posted on

CSRF verification failed. Request aborted. in django rest framework

halo i'm working on a project, using drf, but i'm getting CSRF verification failed. Request aborted at first everything was working, but now when i test my api i keep keep getting,CSRF verification failed below is my setting & view codes

settings file



    'DATE_INPUT_FORMATS': [("%Y-%m-%d")],

    'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
    'PAGE_SIZE': 100

Enter fullscreen mode Exit fullscreen mode


class createProfileView(generics.CreateAPIView):
    queryset = UserProfile.objects.all()
    serializer_class   = UserProfileSerializer
    permission_classes= [permissions.IsAuthenticated]
    parser_classes = (MultiPartParser, FormParser)

    def create(self,request, *args, **kwargs):
        serializer = self.get_serializer(
  , instance = request.user.user_profile 
        headers = self.get_success_headers(
        res  = {
            'msg' : 'Profile successfully created',
            'headers': headers,

        return Response(res)

    def perform_create(self, serializer):
Enter fullscreen mode Exit fullscreen mode

can anyone help

Top comments (1)

sameerahmed123 profile image
sameer-ahmed123 • Edited

hi , csrf verification is Djangos built in security measure , it mostly occurs when there is missing CSRFtoken inside a form .
I suggest you take a look at the templates in your app and add any CSRFtoken that is missing , it will most likely solve your problem

a dango form should look like :

CSRF token