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
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 |
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
{% 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 %} |
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
pip install Flask-OAuth |
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 redirect, url_for, session, request, flash, Blueprint, current_app | |
simple = Blueprint('simple', __name__) | |
oauth = OAuth() | |
twitter = twitter_factory(oauth) | |
@simple.route('/login') | |
def login(): |
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
@twitter.tokengetter | |
def get_twitter_oauth_token(): | |
return session.get('oauth_token') |
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
mkvirtualenv evo; | |
cdvirtualenv | |
# this installs flask, flask-script and everything you need | |
pip install Flask-Evolution | |
touch myapp.py | |
touch manage.py | |
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
# 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' |
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
# myapp.py | |
from flask import Flask | |
app = Flask(__name__) | |
@app.route("/") | |
def hello(): | |
return "Hello World!" | |
if __name__ == "__main__": |
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
# "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 |
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
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 | |