-1

Im working with Django and I have models information that I use in html

Problems I am having

<img src="{% static 'Bola/noticias_imagens/{{ noticia.noticia_imagem }}' %}"

How do I make this code work?

And again I have a text that has some tags like <p> and <br> and when I execute this code, it also shows the tags literally in the website {{ noticia.noticia_texto }} Example of text shown:

"Hello.<p>Goodbye</p>"

Is there a way to fix it?

Ventura
  • 97
  • 12

1 Answers1

0

First question:

{% with 'Bola/noticias_imagens/'|add:noticia.noticia_imagem as image_static %}
  <img src="{% static image_static %}">
{% endwith %}

Second question:

  • You can do it with filter {{ noticia.noticia_texto | safe }}
  • You can do it with tag {% autoescape off %}{{ noticia.noticia_texto }}{% endautoescape %}

But you must understand what are you doing, since this is not safe and could end up with HTML injection attacks.

vasi1y
  • 765
  • 5
  • 13