-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
47 lines (37 loc) · 1.21 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
from flask import Flask, url_for, redirect, render_template, request
from pokedex import get_pokemon
app = Flask(__name__)
app.secret_key = 'cfe8w7r56489[;´0-=6'
@app.route('/', methods=['GET', 'POST'])
def index():
try:
return render_template('index.html')
except:
return redirect(url_for('error'))
@app.route('/search', methods=['GET', 'POST'])
def search():
try:
if request.method == 'GET':
return redirect(url_for('error'))
if request.method == 'POST':
pokemon = request.form['pokemon']
result = get_pokemon(pokemon)
if 'Error' in result:
return redirect(url_for('pokemon_not_found'))
return render_template(
'search.html',
data=result
)
except:
return redirect(url_for('error'))
@app.route('/error', methods=['GET', 'POST'])
def error():
return render_template('error.html')
@app.route('/pokemon-not-found')
def pokemon_not_found():
try:
return render_template('pokemon_not_found.html')
except:
return redirect(url_for('error'))
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=8080)