django rest_framework中将json输出字符强制为utf-8编码
重写了一个继承自JSONRenderer的Utf8JSONRenderer。然后,指定一个renderer_classes属性值即可。
1
2
3
4
5
|
from rest_framework.renderers import JSONRenderer class Utf8JSONRenderer(JSONRenderer): charset = 'utf-8' |
1
2
3
4
5
6
7
8
9
10
|
class DeployPoolViewSet(viewsets.ModelViewSet): """ This viewset automatically provides `list`, `create`, `retrieve`, `update` and `destroy` actions. Additionally we also provide an extra `highlight` action. """ serializer_class = DeployPoolSerializer authentication_classes = (TokenAuthentication,) renderer_classes = (Utf8JSONRenderer,) |