This is an API for the voting service inspired by
the tutorial in the Django docs.
The project structure and some architecture concepts are taken from
the Django Styleguide.
I also want to thank qaa-engineer for his deployment
guide (some installation steps are taken from there).
- Python 3.11.4 or higher
- PostgreSQL 15 or higher
All the steps described below were performed on a computer with Windows 10
installed. If you are not using Windows
,
you may need to replace some shell commands with those that match your OS.
-- Create database named "django_polls_db".
CREATE DATABASE django_polls_db;
-- Create user "django_polls_user". Be sure to use a secure password.
CREATE USER django_polls_user WITH PASSWORD 'password';
-- Set connection parameters for the user.
ALTER ROLE django_polls_user SET client_encoding TO 'utf8';
ALTER ROLE django_polls_user SET default_transaction_isolation TO 'read committed';
ALTER ROLE django_polls_user SET timezone TO 'UTC';
-- Grant the created user access to administer the new database.
GRANT ALL PRIVILEGES ON DATABASE django_polls_db TO django_polls_user;
Clone branch master
and switch to the project directory:
git clone https://github.com/Ceowyllian/DRF-polls-backend.git
cd DRF-polls-backend
Create and activate virtual environment. Install all the necessary packages using pip
(it may take a few minutes):
python -m venv .\venv
venv\Scripts\activate
cd src
pip install -r requirements.txt -r requirements-dev.txt
Create the .env
file in the src
directory, where the manage.py
file is
located. Here are the required environment variables:
DB_URL=postgres://username:password@host:port/db_name
SECRET_KEY=PoTFPuiCcapnlgeYiKHMDY29SAlUj4lWkYBKOtztVDN
DJANGO_DEBUG=False
See the ".env.template" file for a complete list.
Run manage.py command to create all the necessary DB tables:
python manage.py migrate
Create an admin user using the following command:
python manage.py createsuperuser
python manage.py runserver 127.0.0.1:8000