Django ManyToManyField内的图像字段具有错误的URL

时间:2016-05-26 22:15:13

标签: python django django-models django-rest-framework sorl-thumbnail

我的应用中的所有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

0 个答案:

没有答案