Django uploading file not in MEDIA_ROOT path is giving me SuspiciousOperation error

前端 未结 1 2031
不知归路
不知归路 2021-02-07 16:55

I want to upload files to a path that is still in my django project, but in my MEDIA_ROOT path.

When I try to do this I get a SuspiciousOperation

相关标签:
1条回答
  • 2021-02-07 17:20

    Yes there is a way:

    From docs:

    For example, the following code will store uploaded files under /media/photos regardless of what your MEDIA_ROOT setting is:

    from django.db import models
    from django.core.files.storage import FileSystemStorage
    
    fs = FileSystemStorage(location='/media/photos')
    
    class Car(models.Model):
        ...
        photo = models.ImageField(storage=fs)
    
    0 讨论(0)
提交回复
热议问题