Created
January 14, 2013 20:26
-
-
Save kamens/4533077 to your computer and use it in GitHub Desktop.
jsonify proposals
This file contains hidden or 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
############################### | |
# Proposal 1: | |
@jsonify | |
def monkey_function(): | |
if gorillas: | |
# JsonResponse is a new function you'll write that will wrap this in a flask response object, | |
# so @jsonify's code, as-is, will know not to do anything to it | |
return JsonResponse(subtitles.json) | |
else: | |
# in this case @jsonify's code, as-is, will do its thing and automatically turn this into "null" | |
return None | |
############################### | |
# Proposal 2: | |
def monkey_function(): | |
if gorillas: | |
# not using @jsonify, so we can just return JSON | |
return subtitles.json | |
else: | |
# manually JSONifying "None" in this case, instead of using the @jsonify wrapper | |
return api.jsonify.jsonify(None) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment