0

The following is my file deletion code:

path = settings.MEDIA_ROOT
os.remove(os.path.join(path, file_name))

When run I get the following HTTP 500 error:

WindowsError at /project/delete_files/

[Error 2] The system cannot find the file specified: u'C:\DjangoEmt/static/uploads/bridge.jpg'

I have checked the file exists in the directory. Can someone please help me as to why its not working.

Sidenote: I am using ajax in django if this makes any difference.

Community
  • 1
  • 1
Rejoanul Alam
  • 5,435
  • 3
  • 39
  • 68
  • problem solved. path should not be like this i have given. http://stackoverflow.com/questions/185936/delete-folder-contents-in-python – Rejoanul Alam Sep 24 '15 at 08:30

1 Answers1

1

I see in your file path error, a combination of slash and backslash. replace '/' to '\' if your application run on windows system.

path = settings.MEDIA_ROOT
os.remove(os.path.join(path, file_name.replace('/', '\')))