Smart Map in Python Tutorials - Adding a Spatial Database to our Django Backend

EBISYS Tech
1

Welcome to the Smart Map In Python Tutorial Series. In the previous tutorial we created our application skeleton, which comprised of two project folders which was our project folder and our app folder. We then changed the permissions of the EBISYS-Tutorials folder and sub-folders, in order to allow us to open our project in our Atom IDE. And lastly we ran our application and verified that  everything was installed correctly.

In this tutorial we will be adding our spatial database to our application back-end, by editing the configurations in our settings.py file. And then we will run migrate to apply our settings. We will also be downloading external python libraries for GIS related tasks. Lastly we will create our superuser account for the Django admin console, and verify that it was created by running our application and navigating to the admin console.

If you want to check out the video, click on the link below. Remember to Like and Subscribe and hit the Notification button to make sure you're aware of the latest video we will publish.

Smart Map in Python Tutorials - Adding a Spatial Database to our Django Backend (Video)

Bubble plot on open street map

Step 1: Open the Atom IDE from the start menu




Step 2: Open the terminal in the right pane



Step 3: Change to root user

~$ sudo bash

Step 4: Navigate back to the EBISYS-Tutorials folder

~$ cd ..

Step 5: Activate the virtual environment

~$ source venv/bin/activate


Step 6: Navigate back to the WaterWatch folder

~$ cd WaterWatch


Step 7: Install django-leaflet

~$ pip install django-leaflet

comment: django-leaflet will be the gis library that we will use to display maps, and call geoservices.

Step 8: Install geojson

~$ pip install geojson

comment: geojson will be the json serialization library that we will use to serialize our gis data and parse it to the front-end using ajax.

Step 9: Edit the INSTALLED_APPS configuration 

add 'django.contrib.gis'

add 'waterwatchapp'



Step 10: Edit the DATABASES configuration

add 'ENGINE': 'django.contrib.gis.db.backends.postgis'
add 'NAME': 'cptwater'
add 'USER': 'waterwatch'
add 'PASSWORD': 'postgres'
add 'HOST': 'localhost'



Step 11: Run python migrate to apply changes made to the settings.py file

~$ python manage.py migrate



Step 12: Create a django admin superuser account

~$ python manage.py createsuperuser

Step 12: Run the application server

~$ python manage.py runserver

Step 13: Open the django admin console in your web browser

localhost:8000/admin


Step 14: Verify that your superuser account has been created



That is about all we need to cover for adding a spatial database to our Django back-end. I hope you enjoyed it and it will add some value to the projects you are currently busy with.

Stay tuned for the next tutorial in the Smart Map in Python Tutorial Series where we will be adding more GIS support to our application.







Post a Comment

1Comments
Post a Comment