D
D
Dmitry2020-02-07 03:59:29
Django
Dmitry, 2020-02-07 03:59:29

Why does the "a" tag ignore the attachment when rendering the page?

Hello!

I will explain in more detail. There is a page, it has a button, by pressing which an AJAX GET request is sent to the server, the result of render_to_string(template, context) is returned back.

The template has a link:

{% for item in persons_list %}
 <tr>
    <th scope="row">{{ forloop.counter }}</th>
    <td>{{ item.full_name }}</td>
    <td>{{ item.date1 }}</td>
    <td>{{ item.date2 }}</td>
    <td>{{ item.city.name }}</td>
    <td>
       <a href={{ item.get_absolute_url }}>
       <svg class="bi bi-info-fill" width="1em" height="1em" viewBox="0 0 20 20" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
       <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm.93-9.412l-2.29.287-.082.38.45.083c.294.07.352.176.288.469l-.738 3.468c-.194.897.105 1.319.808 1.319.545 0 1.178-.252 1.465-.598l.088-.416c-.2.176-.492.246-.686.246-.275 0-.375-.193-.304-.533l1.002-4.705zM10 7.5a1 1 0 100-2 1 1 0 000 2z" clip-rule="evenodd"></path>
        </svg>
        </a>
      </td>
  </tr>
{% endfor %}


I tested this template without AJAX request, everything worked well. On an AJAX request, the browser closes the link tag before the "svg" tag.
If you look at the result of the AJAX request, it returns correctly:
5e3cb639549ce580894884.jpeg

However, in the browser, I see a similar picture:
5e3cb64648d95592334101.jpeg
Cell code with a link:
<td>
  <a href="/database/person/5"></a>
  <svg class="bi bi-info-fill" width="1em" height="1em" viewBox="0 0 20 20" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
   <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm.93-9.412l-2.29.287-.082.38.45.083c.294.07.352.176.288.469l-.738 3.468c-.194.897.105 1.319.808 1.319.545 0 1.178-.252 1.465-.598l.088-.416c-.2.176-.492.246-.686.246-.275 0-.375-.193-.304-.533l1.002-4.705zM10 7.5a1 1 0 100-2 1 1 0 000 2z" clip-rule="evenodd"></path>
   </svg> 
</td>


Why is this happening and can it be fixed?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mahmudchon, 2020-02-07
@DmitryKyd

Maybe you missed quotes?

<a href="{{ item.get_absolute_url }}">
вместо
<a href={{ item.get_absolute_url }}>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question