Created
July 19, 2012 12:47
-
-
Save drsm79/3143589 to your computer and use it in GitHub Desktop.
Non-trivial Flask blueprint
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 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