Home > Back-end >  how to add html tag in django dictonary
how to add html tag in django dictonary

Time:11-11

I have added a strong tag in Django dict but not working

mylist = [{'hq': 'abc', 'inst': 'Total', 'trade': 'Fitter'}]

I added like this but it rendered the same not highlights

mylist = [{'hq': 'abc', 'inst': '<strong>Total</strong>', 'trade': 'Fitter'}]

CodePudding user response:

Django autoescape all strings when render its in templates for security reasons.

You can disable it when render with the safe template filter or autoescape template tag:

{{ myvar|safe }}

{% autoescape off %}
    {{ myvar }}
{% endautoescape %}


Or mark previously the variable as a safe string.


from django.utils.safestring import mark_safe

mylist = [{
    'hq': 'abc', 
    'inst': mark_safe('<strong>Total</strong>'), 
    'trade': 'Fitter'
}]


  • Related