Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to add html tag in django dictonary

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'}]

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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'
}]


Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading