Skip to content

API for the voting service, inspired by the tutorial in the Django docs.

License

Notifications You must be signed in to change notification settings

Ceowyllian/DRF-polls-backend

Repository files navigation

DRF polls backend

Code style: black

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).


Table of contents

System requirements

  • Python 3.11.4 or higher
  • PostgreSQL 15 or higher

Quick start

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.

1 Create a DB and a user for the django project

-- 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;

2 Clone this repo and install the dependencies

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

3 Configure the environment

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.

4 Create a DB schema and an administrator user

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

5 Run the local server

python manage.py runserver 127.0.0.1:8000

6 Go to the page with OpenAPI documentation - Swagger UI

http://127.0.0.1:8000/oas3/schema/swagger-ui/

About

API for the voting service, inspired by the tutorial in the Django docs.

Topics

Resources

License

Stars

Watchers

Forks