Skip to content

Instantly share code, notes, and snippets.

@colwilson
colwilson / py27_gae_project.sh
Created May 5, 2012 06:46
Install Google App Engine on Ubuntu 12.04
PROJ=py27_gae_project
mkvirtualenv --python=python2.7 ${PROJ}
cdvirtualenv
GAE=1.6.5
wget -O /tmp/gae.zip http://googleappengine.googlecode.com/files/google_appengine_${GAE}.zip
unzip /tmp/gae.zip
GAE_APP_NAME=dummy
mkdir -p gae_app/static
{% block user %}
{% if 'twitter_user' not in session %}
<a href="/login">Sign in with Twitter</a>
{% else %}
<a href="/logout">Sign Out {{session['twitter_user']}}</a>
{% endif %}
{% endblock %}
pip install Flask-OAuth
from flask import redirect, url_for, session, request, flash, Blueprint, current_app
simple = Blueprint('simple', __name__)
oauth = OAuth()
twitter = twitter_factory(oauth)
@simple.route('/login')
def login():
@twitter.tokengetter
def get_twitter_oauth_token():
return session.get('oauth_token')
mkvirtualenv evo;
cdvirtualenv
# this installs flask, flask-script and everything you need
pip install Flask-Evolution
touch myapp.py
touch manage.py
# manage.py
from flaskext.script import Manager
from flask.ext.evolution import Evolution
from myapp import app
manager = Manager(app)
evolution = Evolution(app)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db'
# myapp.py
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":
# "python ./manage.py migrate init" does not create the "migrations" directory for me!
mkdir migrations
python ./manage.py migrate create
Name for the migration: Post
Created new migration file: /mypath/migrations/0001_post.py
import datetime
from flask import current_app
from flask.ext.evolution import BaseMigration
from flask.ext.sqlalchemy import SQLAlchemy
db = SQLAlchemy(current_app)
db.metadata.bind = db.engine