forked from ADI-Labs/labs-f19-challenge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
36 lines (26 loc) · 787 Bytes
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from flask import Flask, render_template
import requests
import json
app = Flask(__name__)
@app.route('/', methods=['GET'])
def main():
return render_template('index.html')
url = "https://www.pokeapi.co/api/v2/pokemon/"
@app.route('/pokemon/<int:id>', methods=['GET', 'POST'])
def ider(id):
#get name
urlid = ''.join([url,str(id)])
r = requests.get(urlid)
data = r.json()
name = data["name"]
return render_template("templateid.html",id=id, name = name)
@app.route('/pokemon/<name>', methods=['GET', 'POST'])
def namer(name):
#get id
urln = ''.join([url,str(name)])
r = requests.get(urln)
data = r.json()
id = data["id"]
return render_template("templatename.html",id=id, name = name)
if __name__ == '__main__':
app.run()