Skip to content Skip to sidebar Skip to footer

Django Tastypie - Serving Emoji That Are Stored In Db

I'm using django and tastypie for my api. the db is MySQL. After a few days of fiddling around i managed to store emoji icons in the db using utf8mb4 character set. When que

Solution 1:

The solution is in DJango settings:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'OPTIONS': {'charset': 'utf8mb4'},
        (...)

Solution 2:

What if you save the JSON dump to a text file and open it with a UTF8 text editor? Will the emoji re-appear?

I suspect that, when displaying the JSON in the browser, the browser falls back to Latin-1 encoding, thus ending up with question marks. There might be a setting in your browser to set the encoding.

Check the "Content-Type" header that comes from your server. Does it say application/json; encoding=utf-8?

Post a Comment for "Django Tastypie - Serving Emoji That Are Stored In Db"