Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
No results found
Show changes
Commits on Source (31)
Showing
with 187 additions and 0 deletions
images/api.png

51 KiB

images/flask-login.png

127 KiB

images/flask-restless-api.png

62.6 KiB

images/flask_and_forms.png

80.4 KiB

images/flask_and_forms_with_questions.png

143 KiB

images/http-request-response-hand-drawn.png

201 KiB

images/internet_protocol.png

60 KiB

images/login.png

102 KiB

images/pythonclass.contentmap.2017-2018.jpg

624 KiB

def a_decorator(a_function):
def wrapper():
print("this gets done before a_function() is called.")
a_function()
print("this gets done after a_function() is called.")
return wrapper
def an_actual_function():
print("i am an_actual_function!")
an_actual_function = a_decorator(an_actual_function)
an_actual_function()
import time
def timing_function(some_function):
"""
Outputs the time a function takes
to execute.
"""
def wrapper():
t1 = time.time()
some_function()
t2 = time.time()
return "Time it took to run the function: " + str((t2 - t1)) + "\n"
return wrapper
@timing_function
def my_function():
num_list = []
for num in (range(0, 10000)):
num_list.append(num)
print("\nSum of all the numbers: " + str((sum(num_list))))
print(my_function())
from flask import Flask
import feedparser # this module reads the rss feeds
from random import randint
app = Flask(__name__)
BBC_FEED = "http://feeds.bbci.co.uk/news/rss.xml"
@app.route("/")
def headline():
feed = feedparser.parse(BBC_FEED)
article = feed['entries'][0]
return """<html>
<body>
<h1> BBC headline </h1>
<b>{0}</b> <br/>
<i>{1}</i> <br/>
<p>{2}</p> <br/>
</body>
</html>""".format(article.get("title"),
article.get("published"), article.get("summary"))
if __name__ == '__main__':
app.run(debug=True,host='0.0.0.0',port=8000)
from flask import Flask, render_template
import feedparser
app = Flask(__name__)
BBC_FEED = "http://feeds.bbci.co.uk/news/rss.xml"
@app.route("/")
def headlines():
feed = feedparser.parse(BBC_FEED)
articles = feed['entries']
return render_template('headlines.html',articles=articles)
if __name__ == '__main__':
app.run(debug=True,host='0.0.0.0',port=8000)
from flask import Flask, render_template
import feedparser
app = Flask(__name__)
BBC_FEED = "http://feeds.bbci.co.uk/news/rss.xml"
@app.route("/")
def headlines():
feed = feedparser.parse(BBC_FEED)
articles = feed['entries']
return render_template('headlines.html',articles=articles)
@app.route("/<word>")
def headlines_word(word):
word = word.lower()
feed = feedparser.parse(BBC_FEED)
articles = feed['entries']
return render_template('headlines_if.html',articles=articles,word=word)
if __name__ == '__main__':
app.run(debug=True,host='0.0.0.0',port=8000)
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return '<center><h1> Hello, World! </h1></center>'
if __name__ == '__main__':
app.run(debug=True,host='0.0.0.0',port=8000)
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def hello_world():
greeting = "hello, world!"
return render_template('hello_world.html',greeting=greeting)
if __name__ == '__main__':
app.run(debug=True,host='0.0.0.0',port=8000)
{% extends "base.html" %}
{% block body %}
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-6"><h1>{{ greeting }}</h1></div>
<div class="col-md-3"></div>
</div>
{% endblock %}
import whats_my_name
print 'if_name = {}'.format( __name__)
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
@app.route('/home')
def home():
greeting = "home!"
return render_template('macros_page.html',greeting=greeting)
@app.route('/about')
def about():
greeting = "about!"
return render_template('macros_page.html',greeting=greeting)
@app.route('/contact')
def contact():
greeting = "contact!"
return render_template('macros_page.html',greeting=greeting)
if __name__ == '__main__':
app.run(debug=True,host='0.0.0.0',port=8000)
from flask import Flask
import feedparser
from random import randint
app = Flask(__name__)
BBC_FEED = "http://feeds.bbci.co.uk/news/rss.xml"
@app.route("/")
def headline():
i = randint(0,9)
feed = feedparser.parse(BBC_FEED)
article = feed['entries'][i]
return """<html>
<body>
<h1> BBC headline </h1>
<b>{0}</b> <br/>
<i>{1}</i> <br/>
<p>{2}</p> <br/>
</body>
</html>""".format(article.get("title"),
article.get("published"), article.get("summary"))
if __name__ == '__main__':
app.run(debug=True,host='0.0.0.0',port=8000)