-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
24 lines (17 loc) · 677 Bytes
/
app.py
File metadata and controls
24 lines (17 loc) · 677 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from flask import Flask, render_template
import requests
app = Flask(__name__)
API_URL = "https://apodapi.herokuapp.com/api/" # 1. Insert API request URL
@app.route('/')
def index():
# 2. Some APIs need a payload or extra data in the fields, set them up here:
payload = {}
# 3. Get the API Response in JSON
api_response = requests.get(API_URL, params=payload).json()
# 4. Extract the information for the template
title = api_response["title"]
image_url = api_response["url"]
# 5. Return the Template with your data
return render_template("index.html", title=title, image_url=image_url)
if __name__ == '__main__':
app.run()