Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6063563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:10:47+00:00 2026-05-23T09:10:47+00:00

{% if posts %} {% for p in posts %} {{p|safe}} {% endfor %}

  • 0
{% if posts %}
    {% for p in posts %}
        {{p|safe}}
    {% endfor %}
{% endif %}

I want this to render html but not javascript, what should I do?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:10:48+00:00Added an answer on May 23, 2026 at 9:10 am

    There is no filter in django that can do what ou want: strip javascript and leave html.

    You can create a custom template filter to do that:

    from django import template
    from django.template.defaultfilters import stringfilter
    from django.utils.safestring import mark_safe
    from django.utils.encoding import force_unicode
    import re
    
    register = template.Library()
    
    @register.filter
    @stringfilter
    def stripjs(value):
        stripped = re.sub(r'<script(?:\s[^>]*)?(>(?:.(?!/script>))*</script>|/>)', \
                          '', force_unicode(value), flags=re.S)
        return mark_safe(stripped)
    

    (Where to put template filters/tags: Custom template tags and filters/Code layout)

    Brief explanation:

    Create a folder named templatetags in your application folder. Add an empty file __init__.py (for it to be a package) and a module file that will contain the filter, my_filters.py. Copy the code in that file.

    In the template file add (before any first use of the filter): {% load my_filters %}

    Usage:

    {% if posts %}
        {% for p in posts %}
            {{ p|stripjs }}
        {% endfor %}
    {% endif %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is perhaps similar to previous posts, but I want to be specific about
Many posts on different aspects of this question but I haven't seen a post
I've encountered posts which have stated, I'd love to use Extension A but it
I have 2 tables: posts tags Tags table is structured like this: post_id tag
I have read some posts on here about not mixing parameters when passing into
I just wondering if it's safe to have form actions like this one: form
As far as I've been able to tell cookielib isnt thread safe; but then
I fear this has been beaten to death, but I'm still struggling with the
Is it safe to do smth like this in first if on the page
So I've looked around to try to find some posts on this and there

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.