-
-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
142 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,5 @@ local_settings.py | |
db.sqlite3 | ||
media | ||
dist/ | ||
*.egg-info/ | ||
*.egg-info/ | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,55 @@ | ||
Quickstart | ||
========== | ||
# Overview | ||
This is a django demonstration project that shows how `django-address` can be used to geocode manually entered postal addresses. | ||
|
||
Get a [Google Maps API Key] and update `GOOGLE_API_KEY` in [settings.py]. | ||
**The Landing Page** | ||
|
||
```bash | ||
# Set up virtual environment | ||
virtualenv env | ||
source env/bin/activate | ||
<img alt="Screenshot of landing page" src="https://user-images.githubusercontent.com/1409710/81486802-50bc4500-920c-11ea-901e-2579e7ce93b2.png" width="450"> | ||
|
||
# Install requirements | ||
pip install -r requirements.txt | ||
**The Admin View** | ||
|
||
# Migrate | ||
python manage.py migrate | ||
<img alt="Screenshot of django admin" src="https://user-images.githubusercontent.com/1409710/81486803-52860880-920c-11ea-8938-b5e216d29c40.png" width="450"> | ||
|
||
# Create a super admin to see results in Django Admin | ||
python manage.py createsuperuser | ||
# Setup | ||
## Create virtual environment | ||
* `virtualenv env` | ||
* `source env/bin/activate` | ||
|
||
## Install python requirements | ||
* `pip install -r requirements.txt` | ||
|
||
## Add Google Maps requirements | ||
Create a Google Cloud Platform project and API Key | ||
* Instructions for setting up an API key here: [Google Maps API Key] | ||
* This requires the set up of a billing with Google | ||
* The key will belong to a "project" in Google Cloud Platform | ||
|
||
### Enable (activate) required Google Maps services for the project your key belongs to | ||
This is hidden under Google Cloud Platform's console menu, under | ||
**Other Google Solutions** > **Google Maps** > **APIs**. ([screenshot](https://user-images.githubusercontent.com/1409710/81484071-9d495580-91f7-11ea-891e-850fd5a225de.png)) | ||
* Google Maps _Javascript API_ | ||
* Google Maps _Places API_ | ||
|
||
### Update this example_site django project's [settings.py]. | ||
* Add your key to `GOOGLE_API_KEY` | ||
|
||
## Migrate | ||
* `python manage.py migrate` | ||
|
||
## Create a super admin to see results in Django Admin | ||
* `python manage.py createsuperuser` | ||
|
||
## Run server | ||
* `python manage.py runserver` | ||
|
||
# The Project | ||
The page shows a simple form entry field | ||
### Troubleshooting Google Maps | ||
Check the browser console on the page for javascript errors. ([Screenshot of an error](https://user-images.githubusercontent.com/1409710/81484063-90c4fd00-91f7-11ea-8833-80a346c77f89.png)) | ||
* `ApiTargetBlockedMapError`: Your API key [needs authorization](https://developers.google.com/maps/documentation/javascript/error-messages#api-target-blocked-map-error) to use the above services. | ||
* `ApiNotActivatedMapError`: Your API key [needs Google Maps services](https://developers.google.com/maps/documentation/javascript/error-messages#api-target-blocked-map-error) to use the above services. | ||
|
||
***NOTE:** There is up to a several minute delay in making changes to project and api key settings. New keys can also take several minutes to be recognized. | ||
|
||
# Run server | ||
python manage.py runserver | ||
``` | ||
|
||
[Google Maps API Key]: https://developers.google.com/maps/documentation/javascript/get-api-key | ||
[settings.py]: example_site/settings.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,28 @@ | ||
from django.conf import settings | ||
from django.shortcuts import render | ||
from address.models import Address | ||
|
||
from address.models import Address | ||
from .forms import PersonForm | ||
|
||
|
||
def home(request): | ||
success = False | ||
addresses = Address.objects.all() | ||
if settings.GOOGLE_API_KEY: | ||
google_api_key_set = True | ||
else: | ||
google_api_key_set = False | ||
|
||
if request.method == 'POST': | ||
form = PersonForm(request.POST) | ||
if form.is_valid(): | ||
pass | ||
success = True | ||
else: | ||
form = PersonForm(initial={'address': Address.objects.first()}) | ||
form = PersonForm(initial={'address': Address.objects.last()}) | ||
|
||
context = {'form': form, | ||
'google_api_key_set': google_api_key_set, | ||
'success': success, | ||
'addresses': addresses} | ||
|
||
return render(request, 'example/home.html', {'form': form}) | ||
return render(request, 'example/home.html', context) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters