Lakshya
Lakshya

Reputation: 51

Unable to Load Images In Django

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

Answers (1)

AKHIL SHALIL
AKHIL SHALIL

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

Related Questions