I want to insert data from json-format into a webapp through flask to put values into html:
spec_player.html:
{% for p in posts: %}
<p>{{p.first_name}}</p>
{% endfor %}
- This works (main.py):
posts = [
{
"id":237,"first_name":"LeBron","height_feet":6,"height_inches":8,"last_name":"James","position":"F",
"team":{"id":14,"abbreviation":"LAL","city":"Los Angeles","conference":"West","division":"Pacific","full_name":"Los Angeles Lakers","name":"Lakers"},"weight_pounds":250
}
]
@app.route("/spec")
def spec_player():
return render_template("spec_player.html", posts=posts)
- This doesn't work (main.py):
posts = [
{
"data":[{"id":237,"first_name":"LeBron","height_feet":6,"height_inches":8,"last_name":"James","position":"F",
"team":{"id":14,"abbreviation":"LAL","city":"Los Angeles","conference":"West","division":"Pacific","full_name":"Los Angeles Lakers","name":"Lakers"},"weight_pounds":250}],
"meta":{"total_pages":1,"current_page":1,"next_page":null,"per_page":25,"total_count":1}
}
]
@app.route("/spec")
def spec_player():
return render_template("spec_player.html", posts=posts)
I wonder if there is a way to get the 2. json-format into the 1. format? (I only get the 2. json-format from an api) OR writing an other query inside html (something like p.data.first_name)?