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.

1

1 Answer 1

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('/', '\')))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.