[Python] Emoji in Django admin form turns into question marks

Discussão em 'Python' iniciado por Stack, Março 6, 2025.

  1. Stack

    Stack Membro Participativo

    In my Django app, I have a setup roughly like so: there is a Model class with a template field

    @python_2_unicode_compatible
    class Message(models.Model):
    template = models.TextField(default=u'', help_text='Template string for message')


    Then inside my view code I have something like

    def view(request, message_id):
    message = get_object_or_404(Message, message_id__iexact=message_id)
    context = {...}
    return HttpResponse(Template(message.template).render(RequestContext(request, context)))


    Then I create Message objects and modify their template field through the Django admin site.

    I want to add emojis or other Unicode characters to one of my messages. I try copy-pasting an emoji into the text field, and save it, but on a refresh it's saved as a string of question marks instead of as the emojis.

    I've double-checked that I haven't touched DEFAULT_CHARSET (should be UTF-8), and I have <meta charset="utf-8"> in the source of both the admin site and the public site. Is there something I'm missing?

    Continue reading...

Compartilhe esta Página