Thursday, March 9, 2023

Install Django with PostgreSQL Support on Amazon Linux

django + PostgreSQL

Install Django with PostgreSQL Support on Amazon Linux

This article will guide you through installing Django with PostgreSQL Support on Amazon Linux.

First, follow this document to install PostgreSQL on Amazon Linux.

 

Continue With Installation

Install required system packages:
sudo yum install -y libpq-devel gcc python3-devel

Initialize Python virtual environment and install required Python packages:

python3 -m venv venv-django source venv-django/bin/activate pip install django psycopg2

Create PostgreSQL database:

sudo -u postgres psql CREATE ROLE djangotest LOGIN ENCRYPTED PASSWORD 'djang0test'; CREATE DATABASE djangotest OWNER djangotest; \q

Create django project:

django-admin startproject testproj cd testproj

Now, edit testproj/settings.py with your preferred text editor. Comment out the DATABASES section and add the following lines:

DATABASES = {    'default': {        'ENGINE': 'django.db.backends.postgresql_psycopg2',        'NAME': 'djangotest',        'USER': 'djangotest',        'PASSWORD': 'djang0test',        'HOST': '127.0.0.1',        'PORT': '5432',    } }

Apply default migrations:

./manage.py migrate

If everything has been configured properly, output very similar to the following one should be generated:

Operations to perform:  Apply all migrations: admin, auth, contenttypes, sessions Running migrations:  Applying contenttypes.0001_initial... OK  Applying auth.0001_initial... OK ... ...  Applying sessions.0001_initial... OK


Created for you by Linuxage

Subscribe to our Telegram channel: https://t.me/linuxage

Join our Telegram chat: https://t.me/linux_age

No comments:

Post a Comment

Install Django with PostgreSQL Support on Amazon Linux

django + PostgreSQL Install Django with PostgreSQL Support on Amazon Linux This article will guide you through installing Django with Postgr...