'CSRF verification failed. Request aborted in Django rest framework sending the request from flutter

I've followed everything mentioned in both documentation of Django rest-framework and Flutter http but still getting the error ..here is my code :

Django

Settings

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'rest_framework.authentication.TokenAuthentication',
    ]
}

View

@csrf_exempt
@permission_classes(["isAuthenticated"])
@api_view(['POST'])
def chanage_image(request):
    data = {}
    if request.method == "POST":
        token = request.META['HTTP_AUTHORIZATION'][6:]
        lang = request.META['HTTP_LANG']
        image = request.data['image']
        main_user = Token.objects.get(key=token).user
        app_user = AppUser.objects.get(main_user=main_user)
        format, imgstr = image.split(';base64,')
        ext = format.split('/')[-1]
        data = ContentFile(base64.b64decode(imgstr), name='temp.' + ext) # You can save this as file instance.
        app_user.image = data
        app_user.save()
        data = {"success": True, "details": AppUserSerializer(
            app_user).data, "message": "Image changed" if lang == "en" else "تم تغيير الصورة"}
        return Response(data, headers=get_headers())

URLS

    path('chanage_image/', chanage_image,name="chanage_image"),

Flutter

Request


    Map<String, dynamic> body = {
      "image": base64Image,
    };


  Future<UserModel> changePlayerImage(Map<String, dynamic> body) async {
    return await httpClient.post('api/user/change-image',
        body: body,
        headers: {'referer': 'https://www.l-dawri.com/'}).then((response) {
      print(response.body);
      return UserModel.fromJson(response.body);
    });
  }

but still in the end am always getting this error :

CSRF verification failed. Request aborted.
You are seeing this message because this site requires a CSRF cookie when submitting forms.


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source