Images from ImageField in Django don't load in template

后端 未结 7 1396
温柔的废话
温柔的废话 2020-12-08 15:58

I\'m building a gallery using Django(1.5.1) on my local machine. In my Album model I have a ImageField. There is a view to show all images of an album. It works

7条回答
  •  不思量自难忘°
    2020-12-08 16:36

    Check in your settings.py you have define MEDIA_ROOT and 'MEDIA_URL' (and they are correct). The MEDIA_ROOT specifies an absolute folder on your machine where media will be stored.

    So for an example:

    MEDIA_ROOT = '/myfolder/'
    

    This would mean it would look for image at:

    /myfolder/images/albums/
    

    Next in your settings.py check your MEDIA_ROOT location: i.e.

    MEDIA_URL = 'http://localhost/myfolder/'
    

    So your images:

    
    

    This would relate to:

    http://localhost/myfolder/images/albums/
    

    Hope this helps.

提交回复
热议问题