Akhil Sundar
Akhil Sundar

Reputation: 1317

Python/Django: Upload an image to media root itself without creating a folder in it

I need to put all my uploaded images in the MEDIA_ROOT directory itself without creating a new folder in it. Following is my model.py:

class Image(models.Model):
    image = models.FileField(_('Upload Image'), upload_to="/media")

But is shows an error "SuspiciousOperation: Attempted access to '/media/image.jpg' denied". Can anyone suggest a proper method to make it done?

Upvotes: 1

Views: 1966

Answers (1)

ndpu
ndpu

Reputation: 22561

Try to remove leading slash from upload_to argument:

# upload_to="/media"
upload_to="media"

or use MEDIA_ROOT as path:

upload_to=MEDIA_ROOT

Upvotes: 1

Related Questions