1
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Django REST Frameworkのjsonが文字化けする件の対処法

Last updated at Posted at 2017-04-16

ある日突然jsonが文字化けしました:joy:

原因: Chromeのアップデート :joy:
以下の通りです....
2017/04/11
http://var.blog.jp/archives/70125676.html

というわけで、REST Frameworkの設定を直して行きます:muscle:

現状クッソ文字化けしている

スクリーンショット 2017-04-16 午後3.12.29.png

:bulb:対処方法

UTF-8を指定したUTF8CharsetJSONRendererクラスの作成
REST Framework のドキュメントにはデフォルトでUTF-8と書いてあるが.........笑

renderers.py
from rest_framework.renderers import JSONRenderer

class UTF8CharsetJSONRenderer(JSONRenderer):
    charset = 'utf-8'
'DEFAULT_RENDERER_CLASSES': (
    # ここをコメントアウト!
    #'rest_framework.renderers.JSONRenderer',
    # 作ったやつに変更する。(僕はdiaryというディレクトリの中にあるので、自分のパスに変更お願いします。)
    'diary.renderers.UTF8CharsetJSONRenderer',
)

:cat:キタ!!!!!!

スクリーンショット 2017-04-19 3.04.17.png

1
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?