Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

323
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda