[Answer]-Django uploaded image cannot display in template

1๐Ÿ‘

โœ…

{{project.photo}} should be {{project.photo.url}}

Update:

<a href="#"><img src="/{{ project.photo.url }}" class="img-responsive" alt="{{ project.name }}"></a>

And ensure that the webserver is set so that requests made to the MEDIA_URL are actually retrieved from the MEDIA_ROOT folder.

If you want to let Django resolve the MEDIA_URL and STATIC_URL add the following lines to your root urls.py.

from django.conf import settings
from django.conf.urls.static import static 
from django.contrib.staticfiles.urls import staticfiles_urlpatterns 

urlpatterns += staticfiles_urlpatterns() 
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Source: https://chat.stackoverflow.com/rooms/28837/discussion-between-paulo-bu-and-sheshkovsky

๐Ÿ‘คEWit

Leave a comment