Last active
December 19, 2015 19:49
-
-
Save pvanliefland/6009424 to your computer and use it in GitHub Desktop.
Using a custom json encoder (lazy strings)
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
from flask import Flask | |
from flask.ext.babel import Babel | |
from utils import LazyAwareJSONEncoder | |
app = Flask(__name__, static_url_path='') | |
app.config.from_pyfile(app.root_path + '/config.cfg') | |
app.json_encoder = LazyAwareJSONEncoder |
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
from flask.json import JSONEncoder | |
from speaklater import is_lazy_string | |
class LazyAwareJSONEncoder(JSONEncoder): | |
def default(self, o): | |
if is_lazy_string(o): | |
return unicode(o) | |
return JSONEncoder.default(self, o) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment