user1088259
user1088259

Reputation: 355

Upload files to specific folder

Structure of my project

untitled2
      --mysite
      --media
           --audio
           --css
           --img
           --js
      untitled2
        --media
        --templates
        --settings.py
        --urls.py

models.py

class Audio(models.Model):
    link_mp     = models.FileField(upload_to='audio/')

settings.py

SITE_ROOT = os.path.dirname(os.path.realpath(__file__))
MEDIA_ROOT = os.path.join(SITE_ROOT, 'media/')

MEDIA_URL = '/media/'

When i upload file from admin my file copy to the untitled2-->untitled2-->media, but i want copy it to utitled2-->media-->audio

Upvotes: 0

Views: 353

Answers (2)

SiddharthaRT
SiddharthaRT

Reputation: 2297

All you have to do is:

MEDIA_ROOT = os.path.join(os.path.dirname(SITE_ROOT), 'media/')

Upvotes: 1

Timmy O'Mahony
Timmy O'Mahony

Reputation: 53971

Your SITE_ROOT is the /untitled2/untitled2/ subfolder where your settings.py is, so your media root is therefore /untitled2/untitled2/media/ and your upload_to is /untitled2/untitled2/media/audio/. Change your media root to use /untitled/media instead

Upvotes: 1

Related Questions