I have installed flask in raspberry pi.
from flask import Flask
from flask import jsonify
import os
import cv2
import numpy as np
app = Flask(__name__)
@app.route('/')
def index():
return 'Hello world'
@app.route('/detect')
def detect():
labels = os.popen('python3 detect.py').read()
return jsonify(labels)
if __name__ == '__main__':
app.run(debug=True, port=8000, host='0.0.0.0')
in the detect() method i have converted the labels into JSON. It is of the format {"John":"Yes","David":"No"} format. But I need to convert this JSON into a HTML table and render it as a html template. so that it looks like
Name Status
John Yes
David No
How do I achieve it?? I have seen lot of questions in StackOverflow but I don't get any correct solution for my question.
{% for name, status in data.items %}<tr><td>{{ name }}</td><td>{{ status }}</td></tr>{% endfor %}where you supply this dictionary with the namedatato your template.return render_template('template.html', labels=labels)not sure if you should jsonify if it comes in as a list then you should be fine using that in jinja2 temaplate -- Flask quickstart is really helpful recommend going through thatreturn render_template('template.html' , data = labels)but it doesn't show any html table