Here's my code written in Python:
from flask import Flask, jsonify, request, render_template
from flask_restful import Api, Resource
app = Flask(__name__)
api = Api(app)
class Tracks(Resource):
@app.route('/')
def get(self):
test = {
"name": "json2html",
"description": "Converts JSON to HTML tabular representation"
}
return render_template('index.html', value=test)
api.add_resource(Tracks, '/tracks')
if __name__ == '__main__':
app.run(port='5002')
Here's my index.html code:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html" charset="utf-8" />
<title>Hello World!</title>
</head>
<body>
<div>
<p>
Hello {{value|safe}}
</p>
</div>
</body>
</html>
The problem is that when I run the server and access the appropriate url page I get html code in browser. It looks like this:
I'd like it to display the dictionary which I pass. How can I solve it?
This question has been marked as a duplicated one but answers from the given link wasn't useful for my problem. I had to create a new question and here's a solution: RESTful API - display returned json in html table