Django widget and field for Google Places Autocomplete (address autofill)
Project description
django-google-places-autocomplete
Django widget and form field for Google Places Autocomplete, so users can pick an address from Google’s suggestions instead of typing it manually.
Requirements
- Django >= 2.2
- Python >= 3.7
- A Google Places API (or Maps JavaScript API with Places library) key
Installation
pip install django-google-places-autocomplete
Or install in editable mode from source:
pip install -e path/to/django-google-places-autocomplete
Settings
- Add the package to
INSTALLED_APPSso static files are found:
INSTALLED_APPS = [
# ...
'django_google_places_autocomplete',
]
- Set your Google Places API key:
GOOGLE_PLACES_API_KEY = 'your-api-key-here'
Restrict the key to your domain and to the Maps JavaScript API / Places API in Google Cloud Console.
Usage
As a widget (ModelForm)
from django import forms
from django_google_places_autocomplete import GooglePlacesAutocompleteWidget
from .models import MyModel
class MyForm(forms.ModelForm):
class Meta:
model = MyModel
fields = '__all__'
widgets = {
'address': GooglePlacesAutocompleteWidget(),
'business_address': GooglePlacesAutocompleteWidget(country_restriction='ca'),
}
As a field
from django import forms
from django_google_places_autocomplete import GooglePlacesAddressField
class MyForm(forms.Form):
address = GooglePlacesAddressField(required=False)
# Restrict to Canada (default is 'ca')
us_address = GooglePlacesAddressField(country_restriction='us')
In templates
Include the form’s media so the Google script and the widget script load:
{{ form.media }}
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Submit</button>
</form>
Options
- country_restriction: Limit suggestions to one country (e.g.
'ca','us'). Default is'ca'. UseNonefor no restriction.
Publishing to PyPI
When ready:
cd path/to/django-google-places-autocomplete
python -m build
twine upload dist/*
License
BSD.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_google_places_autocomplete-0.1.0.tar.gz.
File metadata
- Download URL: django_google_places_autocomplete-0.1.0.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3042953839492e0b41ea4b00fdd33996054208a0b06021e7b32fc636a8f6f483
|
|
| MD5 |
5a45aee7aa940150d210bdd9936e040a
|
|
| BLAKE2b-256 |
23da7e1698b7241704a03e88a33f31dcff44afb1ab7518a83bcc1fb8a67c31b0
|
File details
Details for the file django_google_places_autocomplete-0.1.0-py3-none-any.whl.
File metadata
- Download URL: django_google_places_autocomplete-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5510776d7baf5826e1969f0eba29f5cee1b4f5a2486fe6e34631888cb5da1dac
|
|
| MD5 |
96057ca1e014bcb32aa86fc85e6fe42c
|
|
| BLAKE2b-256 |
077d8c733e48e4b932beefff536feae78cf8a89196a5fcbe462e6feb90314d9b
|