Last active
April 15, 2017 02:42
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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