Sorl-thumbnail bad url's

后端 未结 1 1109
梦如初夏
梦如初夏 2020-12-21 00:09

I setup sorl-thumbnail according to instructions, but none of the images are appearing when I try to use the templatetags in my app.

It appears that the url\'s are n

相关标签:
1条回答
  • 2020-12-21 00:54

    You need to configure MEDIA_URL correctly. The "url" attribute of an ImageFile is basically just a pass-through from the underlying storage backend. For out-of-the-box Django, the upload_to path is appended to MEDIA_URL to generate the URL for a FileField.

    What you have: '' + 'cache/e5/25/e5253a328b9130ecd7d820893f44b0e6.jpg'
    What you want: '/media/' + 'cache/e5/25/e5253a328b9130ecd7d820893f44b0e6.jpg'

    Note: you would need to make sure that MEDIA_URL is aliased/mapped to whatever directory Django is uploading your files to (MEDIA_ROOT).

    ----- EDIT ----
    See the following links to the source of the default Django storage backend. https://code.djangoproject.com/browser/django/tags/releases/1.3/django/core/files/storage.py#L154
    https://code.djangoproject.com/browser/django/tags/releases/1.3/django/core/files/storage.py#L240

    0 讨论(0)
提交回复
热议问题