Skip to main content

A simple django app to use emojis on your website

Project description Latest Version Downloads

Emoji is a port of the GitHub gem gemoji to Django.

This app got two main use cases:

  1. It’ll try to replace items between :: with emojis, for instance : dog : (without the spaces) will become an emoji of a dog (:dog:).

  2. It’ll try to replace unicode characters with emojis, for instance ‘✌️’ with a victory symbol (:v:).

Quick start

  1. Install django-emoji from PyPi:

    pip install django-emoji
  1. Add “emoji” to your INSTALLED_APPS setting like this:

  2. Include the emoji URLconf in your project like this if you want to be able to get a JSON list of emojis:

    url(r'^emoji/', include('emoji.urls')),
  3. Visit to get a json object with all emojis avilable


These are settings that can be configured in your

Settings name



The template string that is used for creating the <img> tag when converting an emoji to an image. Default: <img src="{0}" alt="{1}" title="{2}" class="emoji">


Whether to put the unicode character that corresponds to an emoji as the alt text in replace_unicode. Default: True


Whether to automatically convert HTML encoded unicode characters into emojis. Default: True




The Python class Emoji is a singleton and will return the same instance between instantiations. On load Emoji will load the name of all the emjis and their unicode equivalents into memory.




A list of all known emojis


Replaces all emojis between ::


The name for a given unicode character


Replaces all known unicode emojis


Replaces all HTML encoded unicode characters


The browser version caches all the emojis in localStorage so there won’t be that many roundtrips to the server just to get a list of the emojis.

NOTE: Depends on jQuery or some other library that exports $.get.




Where to fetch the list of all available emojis


Load all emojis from the server


Get the URL to an emoji of a name or return the names of all known emojis


Replace all :: style emojis with images


Empty the browser cache


Replace an emoji using Python templates by loading the tags in your template:

{% load emoji_tags %}
{{ blog_post.body|emoji_replace }}
{{ blog_post.body|emoji_replace_unicode }}
{{ blog_post.body|emoji_replace_html_entities }}

Replace emojis using Javascript (to for instance show a preview before the user saves what it is they are writing):

{% load emoji_tags %}

<script src="{% static 'emoji/js/emoji.js' %}"></script>
{% emoji_load %}

Emoji.get('dog') // => url stub to dog emoji or falsy
Emoji.get() // => all emojis available

Emoji.replace("It's raining :cats: and :dogs:.") // => It's raining <img src="..." alt="cats" class="emoji"> and <img src="..." alt="dogs" class="emoji">

What emoji_load does is that it sets the endpoint to retrieve the listing of all the available emojis and thus only works if the emoji urls has been included.

It is the equivalent of doing:

Emoji.setDataUrl('{% url 'emoji:list.json' %}').load();

Which is also available as template stub:

{% include 'emoji/script.html' %}

Usage from inside Python where the Emoji class mimics some of the behavior of a dict:

from emoji import Emoji
Emoji['dog'] # => url stub to dog emoji or None
'dog' in Emoji # => True
Emoji.keys() # => a list of all emojis by name
Emoji.replace("It's raining :cats: and :dogs:") # => It's raining <img src="..." alt="cats" class="emoji"> and <img src="..." alt="dogs" class="emoji">

Replacing unicode Emojis

Emoji has the ability to give you the name of an emoji from a unicode character. It can also replace every instance of emoji characters in a string with their image replacements.


>>> from emoji import Emoji
>>> Emoji.name_for(u'\U000148b')
>>> Emoji.replace_unicode(u'I send a \U0001f48b!')
I send a <img src="/static/emoji/img/kiss.png" alt="kiss" class="emoji">


For best use of the unicode replacements use a build of Python that was built with wide unicode character support. From version 1.2 there is code added for dealing with unicode surrogate pairs and it should work well on narrow builds. But this has not been production tested so try it out properly. Please report any bugs found.

To test whether you got a narrow or wide build of Python run the following, if you get an exception it means you’re running a narrow build.:

>>> print(unichr(0x0001f48b))
ValueError: unichr() arg not in range(0x10000) (narrow Python build)

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-emoji-1.2.0.tar.gz (4.0 MB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page