In this video we’re going to connect our shops project in Django to our shops database in PostgreSQL.
In addition to having your shops database up and running, you should also have completed the work in video 4 to set up your Django shops project which serves as the root of your website. Also GeoDjango should be added to the
INSTALLED_APPS area of
Python can not natively connect to a Postgres database so we will have to install third party drivers with pip.
The package commonly used for this is
There are different varieties of psycopg2 and you might at first think all you need is the basic one, however this one is not really complete as it requires a C library at runtime called libpq. This puts an unnecessary dependency on the host operating system.
Luckily pyscopg2 is also available as a binary that includes this library and makes our lives easier. For this reason, you will pip install pyscopg2-binary. Two things to note, however. First, pyscopg2-binary is not intended to be a dependency on published, maintained modules. Second, you will most likely need to upgrade pip to install it. Let’s do that now.