Skip to main content

Country-specific Django helpers for U.S.A.

What’s in the U.S.A. localflavor?

  • forms.USPhoneNumberField: A form field that validates input as a U.S. phone number.

  • forms.USSocialSecurityNumberField: A form field that validates input as a U.S. Social Security Number (SSN). A valid SSN must obey the following rules:

    • Format of XXX-XX-XXXX

    • No group of digits consisting entirely of zeroes

    • Leading group of digits cannot be 666

    • Number not in promotional block 987-65-4320 through 987-65-4329

    • Number not one known to be invalid due to widespread promotional use or distribution (e.g., the Woolworth’s number or the 1962 promotional number)

  • forms.USStateField: A form field that validates input as a U.S. state name or abbreviation. It normalizes the input to the standard two-letter postal service abbreviation for the given state.

  • forms.USZipCodeField: A form field that validates input as a U.S. ZIP code. Valid formats are XXXXX or XXXXX-XXXX.

  • forms.USStateSelect: A form Select widget that uses a list of U.S. states/territories as its choices.

  • forms.USPSSelect: A form Select widget that uses a list of U.S Postal Service state, territory and country abbreviations as its choices.

  • models.PhoneNumberField: A CharField that checks that the value is a valid U.S.A.-style phone number (in the format XXX-XXX-XXXX).

  • models.USStateField: A model field that forms represent as a forms.USStateField field and stores the two-letter U.S. state abbreviation in the database.

  • models.USPostalCodeField: A model field that forms represent as a forms.USPSSelect field and stores the two-letter U.S Postal Service abbreviation in the database.

Additionally, a variety of choice tuples are provided in us.us_states, allowing customized model and form fields, and form presentations, for subsets of U.S states, territories and U.S Postal Service abbreviations:

  • us_states.CONTIGUOUS_STATES: A tuple of choices of the postal abbreviations for the contiguous or “lower 48” states (i.e., all except Alaska and Hawaii), plus the District of Columbia.

  • us_states.US_STATES: A tuple of choices of the postal abbreviations for all 50 U.S. states, plus the District of Columbia.

  • us_states.US_TERRITORIES: A tuple of choices of the postal abbreviations for U.S territories: American Samoa, Guam, the Northern Mariana Islands, Puerto Rico and the U.S. Virgin Islands.

  • us_states.ARMED_FORCES_STATES: A tuple of choices of the postal abbreviations of the three U.S military postal “states”: Armed Forces Americas, Armed Forces Europe and Armed Forces Pacific.

  • us_states.COFA_STATES: A tuple of choices of the postal abbreviations of the three independent nations which, under the Compact of Free Association, are served by the U.S. Postal Service: the Federated States of Micronesia, the Marshall Islands and Palau.

  • us_states.OBSOLETE_STATES: A tuple of choices of obsolete U.S Postal Service state abbreviations: the former abbreviation for the Northern Mariana Islands, plus the Panama Canal Zone, the Philippines and the former Pacific trust territories.

  • us_states.STATE_CHOICES: A tuple of choices of all postal abbreviations corresponding to U.S states or territories, and the District of Columbia.

  • us_states.USPS_CHOICES: A tuple of choices of all postal abbreviations recognized by the U.S Postal Service (including all states and territories, the District of Columbia, armed forces “states” and independent nations serviced by USPS).

See the source code for full details.

About localflavors

Django’s “localflavor” packages offer additional functionality for particular countries or cultures.

For example, these might include form fields for your country’s postal codes, phone number formats or government ID numbers.

This code used to live in Django proper – in django.contrib.localflavor – but was separated into standalone packages in Django 1.5 to keep the framework’s core clean.

For a full list of available localflavors, see https://github.com/django/

Release files for django-localflavor-us 1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-localflavor-us 1.1
File Size Uploaded
django-localflavor-us-1.1.tar.gz 6.7 kB Details

Release files / django-localflavor-us-1.1.tar.gz

Download URL django-localflavor-us-1.1.tar.gz
Size 6.7 kB
Tags Source
SHA-256 checksum
How to use checksums
f975c367e72449cd072371c1f91fa5c410940382e319832e80521d3bd46282c5
BLAKE2b-256 checksum
How to use checksums
e33949139e100b9cf3e468af39f2d8922d03e9343edcc09aefecd9e4c3f7042c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.1 This release

1 release file

1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page