0

here is my django code

I get this error when I test my delete function.

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin is therefore not allowed access. The response had HTTP status code 500.

def delete(self):
        ''' Deletes an existed file or folder. '''
        file    = self.request.GET.get('path').lstrip("/")
        path    = os.path.join(self.root,file)
        response = FileManagerResponse(path)
        response.set_response()
        if (self.is_safe_path(path)):
           if os.path.isdir(path):
               shutil.rmtree(path)
           elif os.path.isfile(path):
               os.remove(path)
           return JsonResponse(response.response)
        else:
           return self.fileManagerError(path=file)

here is my angular 4 code

   deleteFile(id) {
       let url = `http://127.0.0.1:8000/files/connectors/python/filemanager?time=1528047056540&mode=delete&path=${id}&_=1528045987217`;
      console.log(url);
      return this.http.get(url);
  }
Vikas
  • 11,859
  • 7
  • 45
  • 69

1 Answers1

0

Have a look at this two post its will be solve your error :

How can I enable CORS on Django REST Framework

AngularJS + Django Rest Framework + CORS ( CSRF Cookie not showing up in client )

Med Elgarnaoui
  • 1,612
  • 1
  • 18
  • 35