On django-rest-framework 2 it works fine:
from rest_framework import rest_response, generics from rest_framework.renderers import JSONRenderer, BrowsableAPIRenderer class SomeView(generics.GenericAPIView): renderer_classes = JSONRenderer, BrowsableAPIRenderer def get(self, request, *args, **kwargs): ...
I do not need to explicitly encode any non-ascii ...
However, after upgrading to DRF 3, the same code now throws the following error:
Traceback (most recent call last): File "/Users/troy/.virtualenvs/publisher/lib/python2.7/site-packages/django/contrib/staticfiles/handlers.py", line 63, in __call__ return self.application(environ, start_response) File "/Users/troy/.virtualenvs/publisher/lib/python2.7/site-packages/whitenoise/base.py", line 119, in __call__ return self.application(environ, start_response) File "/Users/troy/.virtualenvs/publisher/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 189, in __call__ response = self.get_response(request) File "/Users/troy/.virtualenvs/publisher/lib/python2.7/site-packages/django/core/handlers/base.py", line 218, in get_response response = self.handle_uncaught_exception(request, resolver, sys.exc_info()) File "/Users/troy/.virtualenvs/publisher/lib/python2.7/site-packages/django/core/handlers/base.py", line 261, in handle_uncaught_exception return debug.technical_500_response(request, *exc_info) File "/Users/troy/.virtualenvs/publisher/lib/python2.7/site-packages/django_extensions/management/technical_response.py", line 5, in null_technical_500_response six.reraise(exc_type, exc_value, tb) File "/Users/troy/.virtualenvs/publisher/lib/python2.7/site-packages/django/core/handlers/base.py", line 164, in get_response response = response.render() File "/Users/troy/.virtualenvs/publisher/lib/python2.7/site-packages/django/template/response.py", line 158, in render self.content = self.rendered_content File "/Users/troy/.virtualenvs/publisher/lib/python2.7/site-packages/rest_framework/response.py", line 71, in rendered_content ret = renderer.render(self.data, media_type, context) File "/Users/troy/.virtualenvs/publisher/lib/python2.7/site-packages/rest_framework/renderers.py", line 104, in render separators=separators File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 250, in dumps sort_keys=sort_keys, **kw).encode(obj) File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py", line 210, in encode return ''.join(chunks) UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 671: ordinal not in range(128)
I assume that DRF 3 now has some new configuration value, which was the default in DRF 2. I tried to set the REST_FRAMEWORK UNICODE_JSON parameter to True , but I still get the same error ..
Is there a parameter that can make this figure behave like DRF 2? or DRF 3 do I need to track down the non-ascii character in my dictionary and manually encode it?