How To Use PostgreSQL with your Django Application on Ubuntu

Published: 29 December 2022
on channel: MivoCloud
1K
6

Django is a flexible framework for quickly creating Python applications. By default, Django applications are configured to store data into a lightweight SQLite database file. While this works well under some loads, a more traditional database management system can improve performance in production.

In this guide, you’ll install and configure PostgreSQL (often referred to as Postgres) with your Django application. You’ll also install some software packages, create database credentials for your application, and then start and configure a new Django project with this backend.

Commands Used
apt install python3-pip python3-dev libpq-dev postgresql postgresql-contrib
sudo -u postgres psql
CREATE DATABASE myproject;
CREATE USER myproject_user WITH PASSWORD 'myproject_database_password';
ALTER ROLE myproject_user SET client_encoding TO 'utf8';
ALTER ROLE myproject_user SET default_transaction_isolation TO 'read committed';
ALTER ROLE myproject_user SET timezone TO 'UTC';
GRANT ALL PRIVILEGES ON DATABASE myproject TO myproject_user;
\q
pip install virtualenv
mkdir ~/myproject
cd ~/myproject
python3 -m virtualenv myprojectenv
source myprojectenv/bin/activate
pip install Django psycopg2
django-admin startproject myproject .
nano ~/myproject/myproject/settings.py
cd ~/myproject
python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser
ufw allow 8000
python manage.py runserver 0.0.0.0:8000

Useful Links
VPS/VDS -


Watch video How To Use PostgreSQL with your Django Application on Ubuntu online without registration, duration 06 minute 18 second in high hd quality. This video was added by user MivoCloud 29 December 2022, don't forget to share it with your friends and acquaintances, it has been viewed on our site 1 thousand once and liked it 6 people.