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.
pip install django-countriesVerified import paths — ran on the pinned version, not inferred.
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`.
Upgrade Python to 3.8+ or pin `django-countries<8.0.0`.
Ensure correct Python dictionary syntax for `COUNTRIES_OVERRIDE` to prevent parsing errors. Example: `COUNTRIES_OVERRIDE = {'EU': {'names': ['European Union'], 'alpha3': 'EUN', 'numeric': 998}}`.Evaluate your geographical data requirements. If beyond just countries, explore `django-cities-light` or `django-cities` for more comprehensive solutions.
Explicitly access the desired attribute (e.g., `.name`, `.code`, `.flag`) when working with `Country` objects in your code and templates.