0

i have a model with an image field like this

app_icon = models.ImageField(upload_to='icons/')

the project has 'uploads' as media folder, which has subfolders, including 'icons'. The image is correctly uploaded to the 'icons' subfolder but when i try to access it using self.app_icon.path it returns .../uploads/imagename.jpg instead of .../uploads/icons/imagename.jpg so i get file not found error. Even the url doesn't include the 'icons' subfolder

my settings:

MEDIA_URL = '/uploads/'
MEDIA_ROOT = BASE_DIR / 'uploads/'

i can't find any answer to this problem, which seems so random to me.

Ivan Starostin
  • 8,798
  • 5
  • 21
  • 39
Michele Candura
  • 109
  • 1
  • 2
  • 6
  • Perhaps the file was uploaded before settings changes. Take a look at your database, could be the wrong path is there. So update the row or upload once again with current settings. – Ivan Starostin Sep 05 '22 at 18:31

0 Answers0