-1

I want to display a json2table entity for a Flask. That's how the table is generated:

import requests
import json
from json2table import convert
from flask import Flask, render_template, abort, url_for, json, jsonify, request
...
html1 = convert(table1, build_direction=build_direction, table_attributes=table_attributes)
return render_template('index.html', table = html1)

I put {{ table }} in templates/index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form method="POST">
        <input name="text">
        <input type="submit">
    </form>
    <div>
    {{ table }}
    </div>
</body>
</html>

But when I start the app it show me a raw html without formatting

raw html

How can I fix it? What should be done?

Qwerty
  • 19
  • 4
  • Add more code and a screenshot of how you see the actual page rendered on the webpage please. – Federico Baù Dec 25 '20 at 07:46
  • more info added – Qwerty Dec 25 '20 at 08:01
  • Can you also add which packages you are using? I guess some flask-...something? – Federico Baù Dec 25 '20 at 08:13
  • yes, flask, json2table, requests and json – Qwerty Dec 25 '20 at 08:15
  • Ok so, If can look at this later as it's Christmas and can't right now (happy christmas by the way, I dont know if you celebrate it) so if no one else answer this. Having said that let's start to scope in where the issue is.. Can you confirm that any other element is actually rendered? For instance if you pass an argument (take this as example of what I mean [here](https://stackoverflow.com/a/45151521/13903942)) is it rendered? If yes then the issue seems with the package json2table – Federico Baù Dec 25 '20 at 10:32
  • Also I just was that @NavaneethaKrishnan gave an answer, does this solve the issue? – Federico Baù Dec 25 '20 at 10:33
  • Yes, the issue is solved, thank for all – Qwerty Dec 25 '20 at 11:29

1 Answers1

3

Use the safe filter to tell Jinja that the generated HTML is safe to render without escaping.

<div>
{{ table | safe }}
</div>
davidism
  • 121,510
  • 29
  • 395
  • 339
NavaneethaKrishnan
  • 1,213
  • 1
  • 9
  • 22