This is a question about the Korean encoding problem in Python django json response

Asked 2 years ago, Updated 2 years ago, 100 views


def vanalysis(request):
    device = Device.objects.all()
    locations_list = list()
    for d in device:
        try:
            location = d.dev_name.split(';')[2].split(' ')[0]
        except Exception as e:
            location = 'Data error'
        locations_list.append(location)

    data = Counter(locations_list)
    return JsonResponse({'data':data}, content_type=u"application/json")

If you look at the result box on the web,

{"data": {"\uc11c\ucd081\ub3d9": 208, "\uc11c\ucd082\ub3d9": 159, "\ubc18\ud3ec1\ub3d9": 188, "\ubc29\ubc30\ubcf8\ub3d9": 150, "\ubc29\ubc301\ub3d9": 177, "\ubc29\ubc302\ub3d9": 320, "\uc591\uc7ac2\ub3d9": 286, "\uc7a0\uc6d0\ub3d9": 220, "\ubc18\ud3ec4\ub3d9": 210, "\ubc29\ubc303\ub3d9": 208, "\ubc29\ubc304\ub3d9": 253, "\ub0b4\uace1\ub3d9": 166, "\uc11c\ucd083\ub3d9": 331, "\uc11c\ucd084\ub3d9": 163, "\ubc18\ud3ec2\ub3d9": 78, "\uc591\uc7ac1\ub3d9": 341, "\ubc18\ud3ec\ubcf8\ub3d9": 44, "\ubc18\ud3ec3\ub3d9": 17, "\ufffd\ufffd\ubc304\ub3d9": 1, "\ubc29\ubc302\ufffd\ufffd\ufffd": 1, "\uc2e0\uc6d0\ub3d9": 28, "\ub370\uc774\ud130\uc624\ub958": 10, "\uc6b0\uba74\ub3d9": 1, "\uc6b0\uba74\ub3d917(\uc591\uc7ac1\ub3d9)": 1}}

It's coming out like this...

The original key price is mostly Korean. What should I do to make it look like Korean on the web?

python django flask python3.7 json

2022-09-20 20:01

1 Answers

https://docs.python.org/3/howto/unicode.html#:~:text=UTF%2D8%20is%20one%20of,used%20than%20UTF%2D8.)

data = u"\uc11c\ucd081\ub3d9"

print(data)

data = str("\uc11c\ucd081\ub3d9")

print(data)


2022-09-20 20:01

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.