Reputation: 51
I am trying to make a Django Application. Everything is working fine <but I am unable to Render images which are loaded from a Model
I am using SQL Lite in my Local server
GitHub Link of my Code → https://github.com/lakshyagarg911/Django-stack-query
I browsed through Multiple forums but none of them were helpful to me Please help
Settings.py ↓
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
Urls.py ↓
urlpatterns += static(settings.MEDIA_ROOT, document_root=settings.MEDIA_ROOT)
part of my HTML
{% block main_content %}
{% for site in sites %}
<div>
<h1>{{ site.Platform_name }}</h1>
<img src="{{site.Platform_Pic.url}}" alt="">
<p>{{ site.desc }}</p>
<p><a href={{ site.link_to_site }}> Click here to go to {{ site.Platform_name }} </a></p>
</div>
{% endfor %}
{% endblock %}
Upvotes: 0
Views: 57
Reputation: 26
change your urls.py
from -
urlpatterns += static(settings.MEDIA_ROOT, document_root=settings.MEDIA_ROOT)
to -
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Upvotes: 1