Reputation: 87
I am trying to point an image source to a filepath tag I have specified in my views.py
, but for some reason it won't load in the project index file, but will in the specific projects pages. And all my other tags on the same page work, so I'm unsure what I am doing wrong?
<img src="{{ filepath }}" class="card-img-top" alt="Project Image">
Appears in the page as <img src="" class="card-img-top" alt="Project Image">
which shows the alt text.
views.py
def project_details(request, slug):
project = Project.objects.get(slug=slug)
filepath = "/static/img/" + project.title + ".png"
context = {'project': project, 'filepath': filepath}
return render(request, 'projects/project_details.html', context)
Upvotes: 1
Views: 102
Reputation: 87
So, for those who encounter the same issue, the solution I found to work was:
src="{{"/static/img/"|add:project.title|add:".png"}}"
This does require the image to be capitalized however. As the project.title value is, navigate that how you wish.
Upvotes: 1