D
D
Dauren S2016-03-22 18:25:59
Django
Dauren S, 2016-03-22 18:25:59

Django multiple media root?

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
there is a /media folder
but there is also an images folder in the root
is it possible to set another media url in django?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Kuts, 2016-03-25
@fox_12

This can be solved, for example, by writing your own FileStorage
https://docs.djangoproject.com/en/dev/topics/files/
Something like this:

import os
from django.conf import settings
from django.db import models
from django.core.files.storage import FileSystemStorage

my_storage = FileSystemStorage(location=os.path.join(settings.BASE_DIR, 'image'))

class My_model(models.Model):
    file1 = models.FileField()                       # дефолтный MEDIA_ROOT
    image = models.FileField(storage=my_storage)     # пользовательский путь хранения

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question