Skip to content

Instantly share code, notes, and snippets.

@drsm79
Created July 19, 2012 12:47
Show Gist options
  • Save drsm79/3143589 to your computer and use it in GitHub Desktop.
Save drsm79/3143589 to your computer and use it in GitHub Desktop.
Non-trivial Flask blueprint
from flask import Blueprint, current_app, request, jsonify
users = Blueprint('users', __name__)
@users.route('/<username>', methods=['GET', 'POST', 'PUT', 'DELETE'])
def profile(username):
messages = {'GET': 'info about %s' % username,
'POST': 'create account for %s' % username,
'PUT': 'update %s\'s account' % username,
'DELETE': 'remove %s\'s account' % username}
current_app.logger.debug(messages[request.method])
if request.method == 'DELETE':
current_app.logger.warning('%s account deleted' % username)
return jsonify(message=messages[request.method])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment