Skip to content

Commit ff39faf

Browse files
committed
add new blog post on maps in django
1 parent 3708083 commit ff39faf

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Posts and associated code:
77

88
|Post|Code Directory|
99
|---|---|
10-
|How to Add Maps to Django Web App Projects with Mapbox|[maps-django-mapbox](./maps-django-mapbox)|
10+
|[How to Add Maps to Django Web App Projects with Mapbox](https://www.fullstackpython.com/blog/maps-django-web-applications-projects-mapbox.html)|[maps-django-mapbox](./maps-django-mapbox)|
1111
|[Full Stack Python at PyCon US 2018](https://www.fullstackpython.com/blog/full-stack-python-pycon-us-2018.html)|No code in post.|
1212
|[Monitoring Python 3.6 Code on AWS Lambda](https://www.fullstackpython.com/blog/monitor-python-3-6-example-code-aws-lambda-rollbar.html)|[monitor-aws-lambda-python-3-6](./monitor-aws-lambda-python-3-6)|
1313
|[Developing Flask Apps in Docker Containers on macOS](https://www.fullstackpython.com/blog/develop-flask-web-apps-docker-containers-macos.html)|[docker-flask-mac](./docker-flask-mac)|

maps-django-mapbox/djmaps/djmaps/urls.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
1. Import the include() function: from django.urls import include, path
1414
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
1515
"""
16+
from django.conf.urls import include
1617
from django.contrib import admin
1718
from django.urls import path
1819

1920
urlpatterns = [
21+
path('', include('maps.urls')),
2022
path('admin/', admin.site.urls),
2123
]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Interactive maps for Django web apps</title>
5+
<script src='https://api.mapbox.com/mapbox-gl-js/v0.44.2/mapbox-gl.js'></script>
6+
<link href='https://api.mapbox.com/mapbox-gl-js/v0.44.2/mapbox-gl.css' rel='stylesheet' />
7+
</head>
8+
<body>
9+
<h1>Map time!</h1>
10+
<div id='map' width="100%" style='height:400px'></div>
11+
<script>
12+
mapboxgl.accessToken = '{{ mapbox_access_token }}';
13+
var map = new mapboxgl.Map({
14+
container: 'map',
15+
style: 'mapbox://styles/mapbox/satellite-streets-v10',
16+
center: [-77.03, 38.91],
17+
zoom: 9,
18+
bearing: 180
19+
});
20+
</script>
21+
</body>
22+
</html>
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
from django.shortcuts import render
22

3-
# Create your views here.
3+
4+
def default_map(request):
5+
# TODO: move this token to Django settings from an environment variable
6+
# found in the Mapbox account settings and getting started instructions
7+
# see https://www.mapbox.com/account/ under the "Access tokens" section
8+
mapbox_access_token = 'pk.your_mapbox_access_token'
9+
return render(request, 'default.html',
10+
{ 'mapbox_access_token': mapbox_access_token })

0 commit comments

Comments
 (0)