Skip to content

Instantly share code, notes, and snippets.

@pvanliefland
Last active December 19, 2015 19:49
Show Gist options
  • Save pvanliefland/6009424 to your computer and use it in GitHub Desktop.
Save pvanliefland/6009424 to your computer and use it in GitHub Desktop.
Using a custom json encoder (lazy strings)
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
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