I am using an imageField in my Django model and the photo is not being recognized when I try to display it in the html.
Here is my models.py
from django.db import models
class LatestRelease(models.Model):
title = models.CharField(max_length=50)
description = models.CharField(max_length=300)
cover = models.ImageField(upload_to='personal/static/img/')
display = models.BooleanField(default=True)
Here is view.py
from django.shortcuts import render
from personal.models import LatestRelease
def index(request):
releases = LatestRelease.objects.all()
return render(request, "personal/home.html", {'releases': releases})
HTML code
{% for release in releases %}
<img src="{{ release.cover.url }}" class='' height='235' width='235'>
{% endfor %}
So basically, the image path {{ release.cover.url }}
is /personal/static/img/[image name]
and my photos only appear to show up when I use the url path /static/img/[image name]
as the source.
Is there anyway to take /personal
out of the string that is created from {{ release.cover.url }}
? Or to make it so that my img source accepts files under /personal/static/img/[image name]
?