I can’t display image in my template. This is my code:
settings.py
MEDIA_ROOT = os.path.join(DIRNAME, 'media')
MEDIA_URL = ''
STATIC_ROOT = os.path.join(DIRNAME, 'static')
STATIC_URL = '/static/'
# Additional locations of static files
STATICFILES_DIRS = (
os.path.join(DIRNAME, 'my_static'),
)
in my models:
photo = models.ImageField(upload_to='media/images')
in website source(ctrl+U in firefox):
<img class="preview_image" src="static/images/test_1.png" ale="photo" />
How display image correctly?
Change your
MEDIA_URLlike this:Then change
upload_toparameter like this:Add this to your
urls.py:Then access the uploaded image in your template like below: