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
Well I know this question is old but I solved it right now after prove all options:
MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
from django.conf.urls.static import static from django.contrib.staticfiles.urls import staticfiles_urlpatterns from django.conf import settings urlpatterns += staticfiles_urlpatterns() urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
img src="{{ image.image.url }}" alt="{{ image.title }}"
NOTES: Yo don't need MEDIA_URL, be careful with the '/' because image.image.url is absolute, so if you use a namespace then you don't need to add the finish slash.
img src="/namespace_name/{{ image.image.url }}" --> BAD!!! img src="/namescape_name{{ image.image.url }}" --> GOOD!!!