Django Countries

8.2.0 · active · verified Sat Apr 11

django-countries is a Django application that provides a `CountryField` for models, offering all ISO 3166-1 countries as choices. It includes utilities for forms, flag icons as static files, and integrates with Django's internationalization system for translated country names. The current version is 8.2.0, and it maintains an active release cadence with regular updates.

Warnings

Install

Imports

Quickstart

To get started, add `django_countries` to your `INSTALLED_APPS` in `settings.py`. Then, import `CountryField` from `django_countries.fields` and use it in your Django models. This will provide a dropdown with all ISO 3166-1 countries in forms and the admin. Accessing the field on an instance returns a `Country` object with properties like `name` and `flag`.

# settings.py
INSTALLED_APPS = [
    # ...
    'django_countries',
]

# models.py (in your app)
from django.db import models
from django_countries.fields import CountryField

class Person(models.Model):
    name = models.CharField(max_length=100)
    country = CountryField()

# Example usage in a Django shell
# >>> from myapp.models import Person
# >>> person = Person.objects.create(name="Chris", country="NZ")
# >>> person.country
# Country(code='NZ')
# >>> person.country.name
# 'New Zealand'
# >>> person.country.flag
# '/static/flags/nz.gif'

view raw JSON →