diff options
| author | Jon Dufresne <jon.dufresne@gmail.com> | 2019-11-07 02:11:27 -0800 |
|---|---|---|
| committer | Carlton Gibson <carlton.gibson@noumenal.es> | 2019-11-07 11:11:27 +0100 |
| commit | 26554cf5d1e96db10d0d5f4b69683a22fb82fdf8 (patch) | |
| tree | 57c685edd5ce651611e309e539a5eda80cd2f82b /docs/ref | |
| parent | 77aa74cb70dd85497dbade6bc0f394aa41e88c94 (diff) | |
Fixed #29983 -- Replaced os.path() with pathlib.Path in project template and docs.
Thanks Curtis Maloney for the original patch.
Diffstat (limited to 'docs/ref')
| -rw-r--r-- | docs/ref/contrib/gis/tutorial.txt | 16 | ||||
| -rw-r--r-- | docs/ref/templates/api.txt | 6 |
2 files changed, 9 insertions, 13 deletions
diff --git a/docs/ref/contrib/gis/tutorial.txt b/docs/ref/contrib/gis/tutorial.txt index 8fd8d60b62..25c2e35b1c 100644 --- a/docs/ref/contrib/gis/tutorial.txt +++ b/docs/ref/contrib/gis/tutorial.txt @@ -320,14 +320,12 @@ First, invoke the Django shell: $ python manage.py shell -If you downloaded the :ref:`worldborders` data earlier in the -tutorial, then you can determine its path using Python's built-in -``os`` module:: +If you downloaded the :ref:`worldborders` data earlier in the tutorial, then +you can determine its path using Python's :class:`pathlib.Path`:: - >>> import os + >>> from pathlib import Path >>> import world - >>> world_shp = os.path.abspath(os.path.join(os.path.dirname(world.__file__), - ... 'data', 'TM_WORLD_BORDERS-0.3.shp')) + >>> world_shp = Path(world.__file__).resolve().parent / 'data' / 'TM_WORLD_BORDERS-0.3.shp' Now, open the world borders shapefile using GeoDjango's :class:`~django.contrib.gis.gdal.DataSource` interface:: @@ -433,7 +431,7 @@ To import the data, use a LayerMapping in a Python script. Create a file called ``load.py`` inside the ``world`` application, with the following code:: - import os + from pathlib import Path from django.contrib.gis.utils import LayerMapping from .models import WorldBorder @@ -452,9 +450,7 @@ with the following code:: 'mpoly' : 'MULTIPOLYGON', } - world_shp = os.path.abspath( - os.path.join(os.path.dirname(__file__), 'data', 'TM_WORLD_BORDERS-0.3.shp'), - ) + 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) diff --git a/docs/ref/templates/api.txt b/docs/ref/templates/api.txt index becd34c545..f9647fd83a 100644 --- a/docs/ref/templates/api.txt +++ b/docs/ref/templates/api.txt @@ -831,7 +831,7 @@ loaders that come with Django: TEMPLATES = [{ 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [os.path.join(BASE_DIR, 'templates')], + 'DIRS': [BASE_DIR / 'templates'], }] You can also override ``'DIRS'`` and specify specific directories for a @@ -843,7 +843,7 @@ loaders that come with Django: 'loaders': [ ( 'django.template.loaders.filesystem.Loader', - [os.path.join(BASE_DIR, 'templates')], + [BASE_DIR / 'templates'], ), ], }, @@ -917,7 +917,7 @@ loaders that come with Django: TEMPLATES = [{ 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [os.path.join(BASE_DIR, 'templates')], + 'DIRS': [BASE_DIR / 'templates'], 'OPTIONS': { 'loaders': [ ('django.template.loaders.cached.Loader', [ |
