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

118
Views
Django How to escape special character and use slice method in HTML template for json data

before applying json method I was using this {{filt.body|striptags|safe|slice:":250" }} in my html template for escape all special character. Now my data loading from json and how to apply above method in my html template.

models.py

class Blog(models.Model):
       body = RichTextUploadingField()

views.py

class PostJsonListView(View):
    def get(self, *args, **kwargs):

        posts = list(Blog.objects.all().filter(is_published='published') )
        data = list()
        for i in posts:
            data.append({'body':i.body})
            
          
       
        return JsonResponse({'data':data},safe=False)
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can do it in your view like this:

from django.utils.safestring import SafeString
from django.utils.html import strip_tags

for i in posts:
   body = strip_tags(SafeString(i.body))[:250]
   data.append({'body':  body})
about 4 years ago · Juan Pablo Isaza 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!