Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

311
Vistas
Django how can I get this translated markdown to render correctly on a website?

I've taken text from my models and used markdown python extension to turn it into html... but it renders as html as a string on my site like this:

bot:
<p><code>62%</code> Not quite. You got this! Appreciate your efforts</p>
kaik:
<p>ss</p>

Rather than showing the html as a string, I'd like it to format it as html.

My views.py currently:

from django.shortcuts import render
from .models import ChatStream
from django.http import HttpResponseRedirect
import random
import markdown
from django.template import RequestContext

def send(request):
    message = request.POST.get('userMessage', False)
    ip = visitor_ip_address(request)
    response = routes(message, 'website_' + str(ip))
    chatItem = ChatStream(ss= markdown.markdown(response), user= markdown.markdown(message), name=ip)
    chatItem.save()
    return HttpResponseRedirect('/chattr/') 

I'm using markdown to convert the text in my models ChatStream into nicely website formattable text, but rather than formatting as html it just prints the html as a string onto the site.

my chattr.html:

{% for chat_stream in chat %}
    <p>
    {% if forloop.last %}
    {% else %}
        <b>bot:</b> <br> {{chat_stream.ss}} <br>
        <b>{{user}}:</b> <br> {{chat_stream.user}} <br>
    {% endif %}
    </p>
{% endfor %}

It should look like this in the website:

bot:

      62%

Not quite. You got this! Appreciate your efforts

kaik:

ss
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Django's template engine will escape the text, such that if the text contains a < b, it will render it as a &lt; b. You can disable this escaping with the |safe template filter [Django-doc]:

{% for chat_stream in chat %}
    <p>
    {% if forloop.last %}
    {% else %}
        <b>bot:</b> <br> {{ chat_stream.ss|safe }} <br>
        <b>{{ user }}:</b> <br> {{ chat_stream.user }} <br>
    {% endif %}
    </p>
{% endfor %}
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda