C
C
cegthgtlhj2020-09-19 14:11:24
Django
cegthgtlhj, 2020-09-19 14:11:24

How to insert an image symbol from a variable in a Django template?

I try to take the file name of a picture i.db_img_clprinciple_namelike pic1.jpg from the table in a loop and display it in a template. Wherever I insert it - before quotes, after, etc. - an error message appears and in the text of the HTML page on the output it is clear that I am inserting it in the wrong place. Please help with spelling. Thanks to

{% extends 'base.html' %}

{% load i18n static %}

{% block start %}
<div class="p-3 mb-2 bg-primary text-white">
    {% trans "DETAILS" %}
</div>

<table>

{% for i in cleaning_type %}
  <tr>
    <td>{{i.descr}}</td>
  </tr>

  <tr>
    <td>{{i.db_text_app}}</td>
  </tr>

  <tr>
    <td>
      <img class="info-list__img" src="{% static "images/afdetail/{{i.db_img_clprinciple_name}}" %}">
    </td>
  </tr>

{% endfor %}

</table>

{% endblock %}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-09-19
@cegthgtlhj

I don’t understand where such constructions come from, there’s not a word about it in the docks. Open ofdok and read? what is possible to transfer to static https://docs.djangoproject.com/en/3.1/ref/template... PS if this is a model field, then{% tag_name {{ var }} %}
{{ i.db_img_clprinciple_name.url }}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question