Skip to main content

django-postal

(Based upon http://github.com/mthornhill/django-postal)

A django application that provides a location agnostic model for postal addresses.

The motivation behind this project is that most countries have different forms of postal addresses e.g. http://www.bitboost.com/ref/international-address-formats.html , http://en.wikipedia.org/wiki/Address_%28geography%29

This app assumes that all postal addresses worldwide can be made up of 5 optional address lines plus a country code.

It then localizes the title of each line dependant on the country selected. Further information on each address line can be gleaned from django.contrib.localflavor fields and widgets e.g. for the UK

from django import forms
from django.utils.translation import gettext_lazy as _
from django.contrib.localflavor.uk.forms import UKPostcodeField, UKCountySelect

from postal.forms import PostalAddressForm

class GBPostalAddressForm(PostalAddressForm):
    line1 = forms.CharField(label=_(u"Street"), required=False, max_length=50)
    line2 = forms.CharField(label=_(u"Area"), max_length=50)
    city = forms.CharField(label=_(u"Town"), max_length=50)
    state = forms.CharField(label=_(u"County"), widget=UKCountySelect, max_length=50)
    code = UKPostcodeField(label=_(u"Postcode"))

It is hoped that various contributors will contribute address formats per country and that eventually this address information could find it’s way back in to django.contrib.localflavor

Dependencies

django-countries (http://pypi.python.org/pypi/django-countries)

Usage

1. Add django-countries and django-postal to your INSTALLED_APPS in settings.py e.g.:

INSTALLED_APPS = (
    "countries",
    "postal",
    ...
    )
  1. Add a postal_form to your templates:

    some_template.html
    {% load postal_tags %}
    <html>
        <head>
            <script src="{{ MEDIA_URL }}js/jquery-1.4.2.min.js" type="text/javascript" charset="utf-8"></script>
        </head>
    <body>
        <form method="POST" action="">
            {% csrf_token %}
            {{form.as_p}}
            {% monitor_country_change %}
            <script type="text/javascript">
                $('form').monitor_country_change('#id_country');
            </script>
            <input type="submit"/>
        </form>
    </body>
    </html>

Changing the country in the form above should localise the address form.

  1. In your view code add code to save the addressform e.g.:

    from postal.forms import PostalAddressForm
    
    def my_view(request)
        if request.method == "POST":
            address_form = PostalAddressForm(request.POST, prefix=request.POST.get('prefix', ''))
            address_form.save()

How to use localised addresses

Address localisation is turned on by default. To turn off Address l10n in settings.py set:

POSTAL_ADDRESS_L10N = False

Customize address labels and requirement

If you wish to customize the address labels and whether the address line is required or not, you can add the following variables to settings.py:

POSTAL_ADDRESS_LINE1, POSTAL_ADDRESS_LINE2, POSTAL_ADDRESS_CITY, POSTAL_ADDRESS_STATE, POSTAL_ADDRESS_CODE

Each of these variables is set to a tuple of the format ('label', True/False) label is used to label the field, and the second boolean value sets whether the field is required or not, e.g.:

POSTAL_ADDRESS_LINE1 = ("Department", True)

BUILD HISTORY

0.9.6 Remove django-piston requirement Fixed django 1.7 compatibility issues Added Italian Postal Address Form (Thanks to Francesco Facconi for above changes)

0.7.2 Major refactor where all models removed so django-postal just provides localized forms. It is up to the supporting project to define their own address models

0.4 Don’t enforce uniqueness on postal addresses

Developers, How to Contribute

Git foo:

$ git clone git@github.com:mthornhill/django-postal.git
$ cd django-postal
$ virtualenv . --no-site-packages
$ source bin/activate
$ python bootstrap.py
$ bin/buildout -v
$ bin/django syncdb
$ bin/django test postal
$ bin/django runserver

Browse to http://localhost:8000

New countries can be added to the src/postal/forms folder by their 2 letter country code e.g. us

Each country folder contains an __init__.py and a forms.py

forms.py contains the localized address.

Metadata

Release files for lfs-postal 1.0.0

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

Source distribution (sdist)

Source distribution for lfs-postal 1.0.0
File Size Uploaded Provenance Actions
lfs_postal-1.0.0.tar.gz 22.7 kB Without provenance Details for lfs_postal-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for lfs-postal 1.0.0
File Interpreter ABI Platform Actions
lfs_postal-1.0.0-py3-none-any.whl Python 3 none any Details for lfs_postal-1.0.0-py3-none-any.whl

Total release size: 56.5 kB

Release files / lfs_postal-1.0.0.tar.gz

Download URL lfs_postal-1.0.0.tar.gz
Size 22.7 kB
Tags Source
SHA-256 checksum
How to use checksums
322c98ece941f4be760b5de2aeb8f1c4e2e065584933bd74bbb4e950c1dc9662
BLAKE2b-256 checksum
How to use checksums
78ac4a5df97f33fcf886b00c27c7769123a5159d5cc24ee8725e15022c601afd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.3

Release files / lfs_postal-1.0.0-py3-none-any.whl

Download URL lfs_postal-1.0.0-py3-none-any.whl
Size 33.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3951aa6dacc5008f6534c716818b65d7817bc8fa4af19e80fca77afe87ef7ba1
BLAKE2b-256 checksum
How to use checksums
d86ad20820cc9ef5a31b96f871442ed30d6127019b68fff7ca6ffefb7072140b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.3

Security for lfs-postal 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

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