Skip to content

Instantly share code, notes, and snippets.

@linville
Last active April 15, 2017 02:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save linville/ba13562c5bd151f37a10383bf98be15d to your computer and use it in GitHub Desktop.
Save linville/ba13562c5bd151f37a10383bf98be15d to your computer and use it in GitHub Desktop.
A Django template filter to convert a country code to its corresponding Emoji flag.
from django import template
register = template.Library()
OFFSET = ord('🇦') - ord('A')
@register.filter
def flag(code):
return chr(ord(code[0]) + OFFSET) + chr(ord(code[1]) + OFFSET)
# Example:
# flag("US") = "🇺🇸"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment