File tree Expand file tree Collapse file tree 6 files changed +26
-1
lines changed
days/017-020-flask-call-apis/code Expand file tree Collapse file tree 6 files changed +26
-1
lines changed Original file line number Diff line number Diff line change 90
90
env.bak /
91
91
venv.bak /
92
92
* _venv /
93
+ venv_ * /
93
94
94
95
# Spyder project settings
95
96
.spyderproject
Original file line number Diff line number Diff line change
1
+ FLASK_APP=demo.py
Original file line number Diff line number Diff line change @@ -35,6 +35,18 @@ def pokemon():
35
35
return render_template ('pokemon.html' ,
36
36
pokemon = pokemon )
37
37
38
+ @app .route ('/trivia' )
39
+ def trivia ():
40
+ question , answer = get_trivia_question ()
41
+ return render_template ('trivia.html' ,
42
+ question = question ,
43
+ answer = answer )
44
+
45
+ def get_trivia_question ():
46
+ r = requests .get ('https://jservice.io/api/random' )
47
+ data = r .json ()
48
+ return data [0 ]['question' ], data [0 ]['answer' ]
49
+
38
50
39
51
def get_chuck_joke ():
40
52
r = requests .get ('https://api.chucknorris.io/jokes/random' )
Original file line number Diff line number Diff line change 13
13
< button class ="mui-btn mui-btn--raised "> < a href ="/index "> Home</ a > </ button >
14
14
< button class ="mui-btn mui-btn--raised "> < a href ="/100Days "> 100 Days</ a > </ button >
15
15
< button class ="mui-btn mui-btn--raised "> < a href ="/chuck "> Chuck Quote</ a > </ button >
16
- < button class ="mui-btn mui-btn--raised "> < a href ="/pokemon "> Pokemon Colour Picker</ a > </ button >
16
+ < button class ="mui-btn mui-btn--raised "> < a href ="/pokemon "> Pokemon Colour Picker</ a > </ button >
17
+ < button class ="mui-btn mui-btn--raised "> < a href ="/trivia "> Trivia Question</ a > </ button >
18
+
17
19
</ div >
18
20
< hr >
19
21
{% block content %}{% endblock %}
Original file line number Diff line number Diff line change
1
+ {% extends "base.html" %}
2
+
3
+ {% block content %}
4
+ < h1 > Trivia Questions!</ h1 >
5
+ < p > {{question}}</ p >
6
+ < hr >
7
+ < p > {{answer}}</ p >
8
+ {% endblock %}
Original file line number Diff line number Diff line change 1
1
certifi == 2018.8.24
2
2
chardet == 3.0.4
3
3
Click == 7.0
4
+ python-dotenv == 0.9.1
4
5
Flask == 1.0.2
5
6
idna == 2.7
6
7
itsdangerous == 0.24
You can’t perform that action at this time.
0 commit comments