Skip to content

Commit f2cff92

Browse files
committed
added chuck noris joke page
1 parent 40297cd commit f2cff92

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
1+
from datetime import datetime
2+
import requests
13
from flask import render_template
24
from program import app
35

6+
47
@app.route('/')
58
@app.route('/index')
69
def index():
10+
timenow = str(datetime.now())
711
return render_template('index.html', title='Template Demo', time=timenow)
812

13+
914
@app.route('/100Days')
1015
def p100days():
1116
return render_template('100Days.html')
17+
18+
19+
def get_chuck_joke():
20+
r = requests.get('https://api.chucknorris.io/jokes/random')
21+
data = r.json()
22+
return data['value']
23+
24+
25+
@app.route('/chuck')
26+
def chuck():
27+
return render_template('chuck.html', joke=get_chuck_joke())

days/001-004-flask-intro/code/program/templates/base.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<div class="mui-panel">Menu Bar -
1212
<button class="mui-btn mui-btn--raised"><a href="/index">Home</a></button>
1313
<button class="mui-btn mui-btn--raised"><a href="/100Days">100 Days</a></button>
14+
<button class="mui-btn mui-btn--raised"><a href="/chuck">Chuck</a></button>
1415
</div>
1516
<hr>
1617
{% block content %}{% endblock %}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{% extends "base.html" %}
2+
3+
{% block content %}
4+
<h1>Chuck Noris Jokes</h1>
5+
<p> {{ joke }} </p>
6+
{% endblock %}

0 commit comments

Comments
 (0)