我的应用中的所有Imagefields
都正确地返回了urls
,但BaseImages
嵌套在ManyToManyField
内的/media/uploads/img.png
除外。
它们作为部分网址返回,例如http://localhost:8000/media/uploads/img.png
而不是from sorl.thumbnail import ImageField
class BaseImage(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
uploaded_by = models.ForeignKey(settings.AUTH_USER_MODEL)
width = models.IntegerField()
height = models.IntegerField()
image = ImageField(upload_to='uploads/')
class ImagePost(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
user = models.ForeignKey(settings.AUTH_USER_MODEL)
images = models.ManyToManyField(BaseImage)
# settings.py
MEDIA_ROOT = '/Users/Jacob/Documents/Projects/project_media'
MEDIA_URL = '/media/'
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '127.0.0.1:11211',
}
}
"""
SORL THUMBNAIL
"""
THUMBNAIL_DEBUG = True
-
http://localhost:8000/media/uploads/img.png
这些工作正常并返回from sorl.thumbnail import ImageField
class User(...):
avatar = models.ImageField(upload_to='uploads/')
class Group(...):
display_image = ImageField(uplaod_to='uploads/')
:
crontab -e