Skip to main content

Django intl-tel-input

Build Status Code coverage

A Django form widget for international telephone numbers based on the jQuery plugin intl-tel-input.

This package is pre 1.0, so doesn't implement every feature of intl-tel-input. However, it is well tested, and has been stable in production.

Version support

Tested on the following versions of Python and Django.

Package Version support
Python 2.7, 3.4, 3.5, 3.6, 3.7
Django 1.11, 2.0, 2.1

Installation

Install from PyPI.

pip install django-intl-tel-input

Add intl-tel-input to your INSTALLED_APPS, so Django can find the init script.

...
INSTALLED_APPS += ('intl_tel_input',)
...

Usage

Simply add IntlTelInputWidget to your form field.

from intl_tel_input.widgets import IntlTelInputWidget

class MyForm(forms.ModelForm):
    class Meta:
        model = MyModel
        fields = ['foo', 'bar']
        widgets = {
            'bar': IntlTelInputWidget()
        }
...

With a standard form:

class MyForm(forms.Form):
    tel_number = forms.CharField(widget=IntlTelInputWidget())

...

Form media

Include {{ form.media.css }} in the <head> of your template. This will ensure all styles are parsed before the widget is displayed.

If you have included jQuery at the end of your document, then don't forget to update the template where this widget appears with a {{ form.media.js }}. Put it in a block that allows it to come after jQuery.

If you're using crispy-forms, the static content will be inserted automatically beside the input. To prevent this, be sure to set include_media = False on your form helper.

class MyForm(forms.Form):
...
    def __init__(self, *args, **kwargs):
        self.helper = FormHelper()
        self.helper.include_media = False
...

If you need to load all JS in the head, you can make the init.js script wait for the document to be ready with the following snippet.

jQuery(document).ready(
  {{ form.media.js }}
);

All this assumes your form context variable is called form.

Options

The widget can be invoked with keyword arguments which translate to the options available in intl-tel-input.

allow_dropdown

Shows the country dropdown. Default: True

default_code

Country code selected by default. Overridden when using auto_geo_ip. Default: 'us'

preferred_countries

Array of countries that will always appear at the top of the dropdown. Default: ['us', 'gb']

use_default_init

Use the provided init.js to initialize the plugin. Set this to False if you want to provide your own initialization for the plugin. This is useful if, for example, you have your own GeoIP implementation you'd like to use. Default: True

Metadata

Release files for django-intl-tel-input 0.4.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 django-intl-tel-input 0.4.0
File Size Uploaded
django_intl_tel_input-0.4.0.tar.gz 7.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-intl-tel-input 0.4.0
File Interpreter ABI Platform
django_intl_tel_input-0.4.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 17.5 kB

Release files / django_intl_tel_input-0.4.0.tar.gz

Download URL django_intl_tel_input-0.4.0.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
57c8935ba0c9956d190f3b230e6aa099d016bb95914bf5bc988bc5dbac06b21e
BLAKE2b-256 checksum
How to use checksums
1a873463e87198e4981c818184e4cd07469b087d92d81dced66b5ce31bff0a91
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.19

Release files / django_intl_tel_input-0.4.0-py2.py3-none-any.whl

Download URL django_intl_tel_input-0.4.0-py2.py3-none-any.whl
Size 9.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
63f6fc2363472e1c725842df963956d7fca64220cca70da48e16830d8bde1c41
BLAKE2b-256 checksum
How to use checksums
1b47bfdac191af79f288b468ac27f839a3026f12359c404afdb29b1a51bb9b4d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.19

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

1 release file

0.1.1

1 release file

0.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