0
I’m in doubt, the API I’m getting returns me two data types "ID" and "Title" are several id and title and I wanted to play this on my table in a "for" template. I wanted to know if what I did was right because he doesn’t return anything.
code in flask
from flask import Flask, render_template
import requests
import json
app = Flask(__name__)
def game():
url = requests.get("https://jsonplaceholder.typicode.com/posts")
resp = json.loads(url.text)
return resp
@app.route("/")
def index():
return render_template("index.html", data = game())
if __name__ == "__main__":
app.run()
Is the template:
<!doctype html>
<html>
<head>
<title>Minha pagina</title>
<meta charset="utf-8" />
</head>
<body>
<h1>Teste de API</h1>
<br>
<table border = "1">
<tr>
<td align= middle width=100 bgcolor= #DAA520> ID </td>
<td align= middle width=100 bgcolor= #DAA520> TITLE</td>
</tr>
<tr>
{% for i in range(3) %}
<td align= middle width=150>{{resp[i] ["id"]}}</td>
<td align= middle width=150>{{resp[i]["title"]}}</td>
{% endfor %}
</tr>
</table>
</body>
</html>