当前位置:Gxl网 > 互联网 > 上传文件

上传文件

时间:2021-07-01 10:21:17 帮助过:0人阅读

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)

 

else:

MEDIA_ROOT = ‘static/media/images/‘

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://example.com/media/", "http://media.example.com/"
MEDIA_URL = ‘/static/media/images/‘

 

img = models.ImageField(upload_to=‘upload/news/%Y/%m/%d‘, blank=True, null=True)

上传文件,布布扣,bubuko.com

相关教程