Last active
September 22, 2015 00:32
-
-
Save alexrutherford/76d55e57c636ec8059b1 to your computer and use it in GitHub Desktop.
Minimum snippet for using Python's Flask framework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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