TypeError: 'WindowsPath' object is not subscriptable

1,848 views
Skip to first unread message

Richard Ilupeju

unread,
Nov 11, 2020, 2:21:40 AM11/11/20
to geodjango
I recently started the geodjango tutorial from the official Geodjango documentation, and for a while now I've been stuck in the part where I have to implement layer mapping by running a (load.py) file in the django shell.
So this is the code in the file.
"""
from pathlib import Path 
from django.contrib.gis.utils import LayerMapping 
from .models import 

WorldBorder world_mapping = {
                                                      'fips' : 'FIPS', 
                                                      'iso2' : 'ISO2', 
                                                      'iso3' : 'ISO3', 
                                                      'un' : 'UN', 
                                                      'name' :  'NAME', 
                                                      'area' : 'AREA', 
                                                      'pop2005' : 'POP2005',
                                                      'region' : 'REGION',
                                                      'subregion' : 'SUBREGION', 
                                                      'lon' : 'LON',
                                                      'lat' : 'LAT', 
                                                      'mpoly' : 'MULTIPOLYGON', 
                                                      }
  world_shp = Path(__file__).resolve().parent / 'data' / 'TM_WORLD_BORDERS-0.3.shp' 

def run(verbose=True): 
    lm = LayerMapping(WorldBorder, world_shp, world_mapping, transform=False)                  lm.save(strict=True, verbose=verbose)  


And this is the error I'm getting
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "C:\Users\ILUPEJU\Desktop\Web Stuff\geodjango\world\load.py", line 23, in run
    lm = LayerMapping(WorldBorder, world_shp, world_mapping, transform=False)
  File "C:\Users\ILUPEJU\Envs\stext\lib\site-packages\django\contrib\gis\utils\layermapping.py", line 99, in __init__
    self.layer = self.ds[layer]
TypeError: 'WindowsPath' object is not subscriptable


Reply all
Reply to author
Forward
0 new messages