Use Flask and render_template to pass data to an HTML template.
Use Python requests to get API data.
Display the data dynamically with Jinja.
Use if/else and for loops where needed to create HTML elements.
@app.route('/nasa')
def nasa():
#Get NASA API data
today = str(date.today()) #Make sure to import date from time
response = requests.get("https://api.nasa.gov/planetary/apod?api_key=GdHGB6sVubfXxXmS8Gsp5N8f9INB4hDuQqdTafOl&date="+today)
#Parses the data as a JSON object
data= response.json()
#Passes the JSON data into the HTML template
return render_template('nasa.html' , data=data)
{% if data['media_type'] == "video" %}
<iframe width="420" height="315" src="{{data['url']}}"> </iframe>
{% else %}
<img class="aotd-img" src="{{data['url']}}">
{% endif %}