Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 4fcde5b0f8
Fetching contributors…

Cannot retrieve contributors at this time

46 lines (37 sloc) 1.208 kb
import os
import simplejson
from flask import Flask, render_template, redirect, url_for, request, make_response
from flaskext.sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('DATABASE_URL')
if not os.environ.get('PROD'):
app.config['SQLALCHEMY_ECHO'] = True
app.debug = True
db = SQLAlchemy(app)
class Bar(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(128))
def __init__(self, name): = name
def index():
return render_template('index.html')
@app.route("/addBar", methods=['POST'])
def addBar():
bar = Bar(request.form['name'])
return redirect(url_for('index'))
def listBars():
bars = Bar.query.all()
bar_list = []
for bar in bars:
bar_list.append({'id':, 'name':})
response = make_response()
response.headers['Content-Type'] = 'application/json' = simplejson.dumps(bar_list)
return response
if __name__ == "__main__":
port = int(os.environ.get("PORT", 5000))'', port=port)
Jump to Line
Something went wrong with that request. Please try again.