Search code examples
pythonhtmldjangojson2html

how to convert python to html in django template


I am using json2html to convert json values to html tables in my views.py

render(request, 'home.html', {'value': json2html.convert(json=result)})

where result has json data.

The above gives me html for json but in home.html template it is not displayed in html table format instead it is displaying like below on the site

<ul><li><table border="1"><tr><th>name</th><td>Test</td></tr><tr><th>

my home.html the code looks like this

<html>
<body>
{{ value }}
</body>
</html>

the variable value has the converted html table code but it is displaying as raw instead it should render as html code. How to do this ?


Solution

  • Tell Django that a string is safe and will not be automatically escaped:

    {{ value|safe }}