Reputation: 1820
I'm developing in Django on Windows XP using the manage.py runserver
command to serve files. Apache isn't involved. When I login to the administration and try to delete a file I get a "SuspiciousOperation" error.
Here's the traceback:
http://dpaste.com/123112/
Here's my full model:
http://dpaste.com/hold/123110/
How can I get rid of this "SuspiciousOperation" error?
EDIT: Here are my media settings:
MEDIA_ROOT = 'C:/Server/Projects/postnzb/static/'
MEDIA_URL = '/static/'
Upvotes: 2
Views: 2240
Reputation: 20666
What is your MEDIA_ROOT
in settings.py
? From the back-trace, it seems you have set your MEDIA_ROOT
to /static/
.
This error is coming since Django is trying to access /static/
to which it has no access. Put an absolute pathname for MEDIA_ROOT
like C:/Documents/static/
and give full permissions to Django to access that directory.
That should solve your problem.
Addendum: Since your MEDIA_ROOT
seems to be OK, I am guessing that you are using MEDIA_URL
for deleting the file instead of MEDIA_ROOT
. Indeed, from the error it seems that Django was trying to access the /static/files/8.nzb
and was denied access. Clearly, /static/
is your MEDIA_URL
and not your MEDIA_ROOT
. The model methods should never try accessing the files using the MEDIA_URL
. I am sure a review of your code will spot the error.
Update: I skimmed your code and it seems you are setting File.nzb
to %(1)sfiles/%(2)s.nzb' % {'1': settings.MEDIA_URL, '2': self.pk}
which uses its MEDIA_URL
and then in the delete()
method you are calling the delete()
method of the super-class of File
as super(File, self).delete()
which is obviously wrong as it will try deleting File.nzb
and will try accessing the file through the MEDIA_URL
. Fixing that will get rid of the error. I will leave the exact solution as an exercise to you :)
Upvotes: 5