update Django integration (#971)
* update Django integration * address PR comments
This commit is contained in:
@@ -105,7 +105,7 @@ specify the URL for the service layer in the ``data`` field.
|
||||
|
||||
* ``id_field`` will often be ``OBJECTID``, ``objectid``, or ``FID``.
|
||||
* If the map or feature service is not shared publicly, the ``username`` and ``password`` fields can be set in the
|
||||
configuration to authenticate into the service.
|
||||
configuration to authenticate into the service.
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
@@ -310,7 +310,7 @@ relies on `sodapy <https://github.com/xmunoz/sodapy>`.
|
||||
* ``resource_id`` is the 4x4 resource id pattern.
|
||||
* ``geom_field`` is required for bbox queries to work.
|
||||
* ``token`` is optional and can be included in the configuration to pass
|
||||
an `app token <https://dev.socrata.com/docs/app-tokens.html>` to Socrata.
|
||||
an `app token <https://dev.socrata.com/docs/app-tokens.html>` to Socrata.
|
||||
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
@@ -1,103 +0,0 @@
|
||||
.. _downstream:
|
||||
|
||||
Downstream Projects
|
||||
=======
|
||||
|
||||
Downstreaming `pygeoapi` project with various python frameworks.
|
||||
|
||||
------------------
|
||||
|
||||
In this page, we'll demonstrate how to downstream `pygeoapi` project with various python frameworks.
|
||||
|
||||
|
||||
Django
|
||||
^^^^^^
|
||||
|
||||
Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design. Click `here <https://www.djangoproject.com/>`_ to read more about Django.
|
||||
|
||||
In this section we create a sample django project and use `pygeoapi` package as a pluggable django application and serve all the capabilities of `pygeoapi` using Django. For the truly impatient developers, there is a Django `sample_project` in the source code.
|
||||
|
||||
To create everything from scratch please follow these steps :
|
||||
|
||||
- Create a Project folder and create a fresh virtual environment using your preferred tool. e.g.
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
python3 -m venv env
|
||||
|
||||
Once created, activate it.
|
||||
|
||||
- Install the following dependencies
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
pip install Django pygeoapi
|
||||
|
||||
- Create a django project in a directory and cd into it.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
django-admin startproject sampleproject
|
||||
cd /sampleproject
|
||||
|
||||
- Download `pygeoapi-config.yml` using
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
curl -O https://raw.githubusercontent.com/geopython/pygeoapi/django_pygeoapi/sample_project/pygeoapi-config.yml
|
||||
|
||||
and put it in the same folder at root level.
|
||||
|
||||
- Set environment variable
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
export PYGEOAPI_CONFIG=pygeoapi-config.yml
|
||||
export PYGEOAPI_OPENAPI=example-openapi.yml
|
||||
|
||||
- Run `python manage.py collectstatic` to get all static files.
|
||||
- Generate OpenAPI document using following `pygeoapi` command
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
pygeoapi openapi generate $PYGEOAPI_CONFIG --output-file $PYGEOAPI_OPENAPI
|
||||
|
||||
- Update Django `sampleproject/settings.py` file as per following
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import os
|
||||
from pygeoapi.django_app import config
|
||||
|
||||
INSTALLED_APPS = [
|
||||
# other apps
|
||||
....
|
||||
#pygeoapi app
|
||||
'pygeoapi'
|
||||
]
|
||||
|
||||
# Put following setting after STATIC_URL
|
||||
STATIC_ROOT = os.path.join( BASE_DIR / 'assets')
|
||||
|
||||
# Specific pygeoapi setting
|
||||
PYGEOAPI_CONFIG = config()
|
||||
...
|
||||
|
||||
- Update Django `sampleproject/urls.py` file to run pygeoapi at e.g. `pga` path
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from django.contrib import admin
|
||||
from django.urls import path, include
|
||||
from pygeoapi.django_pygeoapi import urls
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
path('pga/', include(urls)) # added here
|
||||
]
|
||||
|
||||
- Update pygeoapi `pygeoapi-config.yml` file with following settings
|
||||
|
||||
1. Update the `url` property under `server` in `pygeoapi-config.yml` accordingly to your django project url. e.g. In this case the path set is `pga` .
|
||||
2. Update all data paths e.g. `tests/data/ne_110m_lakes.geojson` to match with the absolute path of the pygeoapi project directory.
|
||||
|
||||
- Run Django project using `python manage.py runserver`. Once server starts, head over to `localhost:8000/pga` to see `pygeoapi` running.
|
||||
@@ -23,7 +23,6 @@ pygeoapi |release| documentation
|
||||
configuration
|
||||
administration
|
||||
running
|
||||
downstream
|
||||
running-with-docker
|
||||
tour
|
||||
openapi
|
||||
|
||||
@@ -181,6 +181,26 @@ is simple to run from the command, e.g:
|
||||
.. note::
|
||||
Uvicorn is as easy to install as ``pip install uvicorn``
|
||||
|
||||
|
||||
Django
|
||||
^^^^^^
|
||||
|
||||
`Django`_ is a Python web framework that encourages rapid development and clean, pragmatic design. Assuming
|
||||
a Django install/enabled application:
|
||||
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
pygeoapi serve --django
|
||||
|
||||
|
||||
To integrate pygeoapi as part of another Django project in a pluggable way the truly impatient developers can
|
||||
see `examples/django/sample_project/README.md` for a complete Django application.
|
||||
|
||||
As a result, your Django application will be available at http://localhost:5000/ and pygeoapi will be available
|
||||
at http://localhost:5000/oapi
|
||||
|
||||
|
||||
Summary
|
||||
-------
|
||||
|
||||
@@ -199,3 +219,4 @@ and modify accordingly.
|
||||
.. _`Gunicorn settings`: http://docs.gunicorn.org/en/stable/settings.html
|
||||
.. _`Uvicorn`: https://www.uvicorn.org
|
||||
.. _`mod_wsgi`: https://modwsgi.readthedocs.io
|
||||
.. _`Django`: https://djangoproject.com
|
||||
|
||||
Reference in New Issue
Block a user