Skip to content

Instantly share code, notes, and snippets.

@alexrutherford
Last active September 22, 2015 00:32
Show Gist options
  • Save alexrutherford/76d55e57c636ec8059b1 to your computer and use it in GitHub Desktop.
Save alexrutherford/76d55e57c636ec8059b1 to your computer and use it in GitHub Desktop.
Minimum snippet for using Python's Flask framework
from flask import Flask,render_template,jsonify,make_response,request,current_app,url_for
import pymysql
app=Flask('yt_db')
api=Api(app)
##########################
@app.route("/hello")
def hello():
return 'Hello world'
# www.test.com:5000/hello will display a page with just the text 'Hello World'
##########################
@app.route("/count")
def count():
conn = pymssql.connect(server, user, password, "tempdb")
cursor = conn.cursor()
cursor.execute("""count(name) from stuff""")
result = cursor.fetchone()
return result
# www.test.com:5000/count will display a page with just the number of records
if __name__=='__main__':
app.run('http:www.test.com:5000')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment