How To Use PostgreSQL with your Django Application on Ubuntu

preview_player
Показать описание
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 .
cd ~/myproject
ufw allow 8000

Useful Links
Рекомендации по теме