Skip to content

Instantly share code, notes, and snippets.

Last active January 21, 2020 19:26
What would you like to do?
An example flask application for retrieving and displaying facts about cats.
import os
from flask import Flask, render_template
import requests
app = Flask(__name__)
def get_cat_fact():
cat_facts_url = ''
response = requests.get(cat_facts_url)
if response.status_code is 200:
return response.json()['fact']
return 'Sorry, could not get cat fact!'
def index():
"""Index page of the site"""
cat_fact_string = 'Hello there, here is your cat fact: {}'.format(get_cat_fact())
return render_template('base.html', cat_fact=cat_fact_string)
if __name__ == '__main__':, host='', port=int(os.environ.get('PORT', 5000)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment