I'm trying to display a photo on a page.
My code:
# views.py
def productHTML(request, uuid):
product = Product.objects.get(id = uuid)
path = product.category.path_to_foto
slovar = {"product": product, "category": path}
return render(request, "product.html", slovar)
productHTML.html
:
{% extends 'products.html' %}
{% load static%}
{% block title %}Продукт{% endblock %}
{% block page_content %}
{% if product %}
<p>Путь до фото: {{path}} </p>
<img src="{% static {{ path }} %}" alt="product picture" width="540" height="300">
<p><b>Категоия: </b>{{ product.category }} </p>
<p><b>Название: </b>{{ product.name }}</p>
<p><b>Марка: </b>{{ product.marka }}</p>
<p><b>Привод: </b>{{ product.privod }}</p>
<p><b>Лошадиные силы: </b>{{ product.loshad_sila }}</p>
<p><b>Коробка передач: </b>{{ product.box_peredach }}</p>
<p><b>Объём двигателя: </b>{{ product.volume_dvigatel }}
<p><b>Цена: Бесплатно</p>
<button>КУПИТЬ</button>
{% endif %}
{% endblock %}
Through Product.objects.get(id = uuid)
I get a specific product. Through product.category.path_to_foto
I get the path to the photo of this product. After that I'm trying to put this path into a variable and display it on the html page, but I get an error:
django.template.exceptions.TemplateSyntaxError: Could not parse the remainder: '{{' from '{{'
All product photos are stored in static/media
If you need any details, I am ready to provide them.
I tried to change the path to the photo. For example, I tried to replace media/<file>
with static/media/<file>
to no avail. I also tried to implement the variable differently, without success.