Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

310
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!