Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sammachin/7cf1c361e84bb3098e39926ca0f87477 to your computer and use it in GitHub Desktop.
Save sammachin/7cf1c361e84bb3098e39926ca0f87477 to your computer and use it in GitHub Desktop.
Django template converts country code to Emoji
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