Giter Club home page Giter Club logo

Comments (11)

mattmakai avatar mattmakai commented on September 14, 2024

hmm, I'm not sure what the problem is without further info. the map that shows up on this page for the tutorial https://www.fullstackpython.com/blog/maps-django-web-applications-projects-mapbox.html is roughly the same as what you should have in a Django application as well

from fullstackpython.com.

dstevenscal avatar dstevenscal commented on September 14, 2024

Unfortunately no error message is being displayed by django.

I've put the code from default.html and urls.py below - maybe I missed something?
I've changed my actual token to 'mymapboxtoken'

<!DOCTYPE html>
<html>
  <head>
    <title>Hey Interactive maps for Django web apps</title>
    <script src='https://api.mapbox.com/mapbox-gl-js/v0.44.2/mapbox-gl.js'></script>
    <link href='https://api.mapbox.com/mapbox-gl-js/v0.44.2/mapbox-gl.css' rel='stylesheet' />
  </head>
  <body>
   <h1>Map time and stuff3</h1>
   <div id='map' width="100%" style='height:400px'></div>
   <script>
    mapboxgl.accessToken = {{ 'mymapboxtoken' }};
    var map = new mapboxgl.Map({
      container: 'HTMLElement',
     style: 'mapbox://styles/mapbox/satellite-streets-v10a',
     center: [-77.03, 38.91],
     zoom: 9,
     bearing: 180
    });
   </script>
  </body>
</html>

from views.py

from django.shortcuts import render

# Create your views here.

def default_map(request):
    # TODO: move this token to Django settings from an environment variable
    # found in the Mapbox account settings and getting started instructions
    # see https://www.mapbox.com/account/ under the "Access tokens" section
    mapbox_access_token = 'mymapboxtoken'
    return render(request, 'default.html',
                  { 'mapbox_access_token': mapbox_access_token })

from fullstackpython.com.

mattmakai avatar mattmakai commented on September 14, 2024

you shouldn't have quotes around your mapbox token like that: mapboxgl.accessToken = {{ 'mymapboxtoken' }};

should be mapboxgl.accessToken = '{{ mymapboxtoken }}';

from fullstackpython.com.

mattmakai avatar mattmakai commented on September 14, 2024

also your container should not be 'HTMLElement', it's 'map' because that's what your div is id'd

from fullstackpython.com.

dstevenscal avatar dstevenscal commented on September 14, 2024

When I take away the quotes from the token I get message 'pk' is not defined - the first 3 characters are pk.

from fullstackpython.com.

mattmakai avatar mattmakai commented on September 14, 2024

sounds like you're not properly passing in the variable. can you start with the example given in the blog post then modify from there? that's why you're having trouble. don't customize before you get the basic scenario working

from fullstackpython.com.

dstevenscal avatar dstevenscal commented on September 14, 2024

from fullstackpython.com.

mattmakai avatar mattmakai commented on September 14, 2024

from fullstackpython.com.

dstevenscal avatar dstevenscal commented on September 14, 2024

from fullstackpython.com.

dstevenscal avatar dstevenscal commented on September 14, 2024

I started from scratch, recreating the project again, and I'm getting the same blank page.
Here's what my console says:
image

Not getting any error message.
djangopage

I tried to create a deliberate error by changing default.html from:

<title>Interactive maps for Django web apps</title> <script src='https://api.mapbox.com/mapbox-gl-js/v0.44.2/mapbox-gl.js'></script>

Map time!

<script> mapboxgl.accessToken = {{ 'mymaptoken' }}; var map = new mapboxgl.Map({ container: 'map', style: 'mapbox://styles/mapbox/streets-v10' }); </script>

Which I changed to:

<title>Interactive maps for Django web apps</title> <script src='https://nosuchapi.mapbox.com/mapbox-gl-js/v0.44.2/mapbox-gl.js'></script>

Map time! diff

<script> mapboxgl.accessToken = {{ 'mytoken' }}; var map = new mapboxgl.Map({ container: 'map', style: 'nosuchmapbox://styles/mapbox/streets-v10' }); </script>

Map time! diff shows up, but no error message. It seems like nothing is actually reaching mapbox. The script isn't getting run at all.

from fullstackpython.com.

mattmakai avatar mattmakai commented on September 14, 2024

Chrome dev tools console output debugging is your best bet here. You should write to Mapbox support, perhaps they can easily identify what's going on.

from fullstackpython.com.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.