Django media image not showing up in template but can acces it via .../media/thumbnail/image.png

Altough context does render in html, i can use other variables but cant accsess the image. My code is:


    {% for a in Manga %}
        <div class="manga_container">
            <div class="manga_image">
                <img src="{{ x.manga_image.url }}" alt="">


class Manga(models.Model):
    manga_name = models.CharField(max_length= 255, default="null")
    manga_image = models.ImageField(upload_to="thumbnail", default="thumbnail/noimage.png")

    def __str__(self):
        return f"{}, {self.manga_name}"

and lastly view:

def Index(request):
    manga = Manga.objects.all().values()
    chapter = Chapter.objects.all().values()
    fansub = Fansub.objects.all().values()

    context= {
        "Manga": manga,
        "Chapter": chapter,
        "Fansub": fansub,

    template = loader.get_template("Index.html")

    return HttpResponse(template.render(context, request))

ı have used function based views since ı have to deal with multiple models at once.

my media and url is as following:

import os

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
urlpatterns = [
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

I have put that p tag for me to see its url and as you can see it was in the right place, when i go to i can see it and it does come up to my screen. i have tried most of the ways i could have think of. I want to see the image on my html and i didnt touch anything so it is basicly default image as i have configured it to.

Instead of manga = Manga.objects.all().values() use manga = Manga.objects.all()

Back to Top