上传文件
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)