Name | Version | Name II | Version |
---|---|---|---|
Python | 3.10 | Nginx | |
Django | 4.1.0 | Gunicorn | |
Ubuntu | 20.10.14 | Gevent | |
Docker | 20.04 | Redis | |
Git | 2.33 | RabbitMQ | |
Postgres | 14.3 | Celery | |
docker-compose | 14.3 | Prometheus |
The first thing to do is to clone the repository
Create a virtual environment to install dependencies inside it and activate it.
Install Virtualenv package
pip install virtualenv --upgrade
Create a virtual environment
virtualenv .env
Activate virtual environment in linux
source .env/bin/activate
Activate virtual environment in windows
.\.env\Scripts\activate.bat
To install dependencies you can use bellow command.
pip install django
To save all dependencies version always after installation use bellow command.
pip freeze > requirements.txt
To install all current dependencies on your environment:
pip install -r requirements.txt
Install pipenv package
pip install pipenv --upgrade
activate virtual environment
pipenv shell
To install a package you can use bellow command. One of feature of this virtual environment is to lock the dependencies automatically.
NOTICE: It maybe slow on your local machine.
pipenv install django
To install all current dependencies on your environment:
pipenv install
Add a secret key to settings.ini
file.
import secrets
print(secrets.token_urlsafe(50))
TIP: Copy generated secret key to settings.ini
with SECRET_KEY
.
SECRET_KEY=<your-strong-password>
Now you need to config your database configuration. Database of current project is postgresql
.
# your database name that is created on postgreSQL
DB_NAME=
# Enter your database user and it must have access to the created db.
DB_USER=
# Enter your specified user's database password.
DB_PASSWORD=
# Accessible port of the installed database (default is `5432`)
DB_PORT=
# Local Database is `localhost` if you are using docker must enter `docker-service-name`
DB_HOST=
# Select a test database name for the created user.
DB_TEST=
In this section you should know how to create a database with the user in PostgreSQL
Create Database on your postgres DBMS
CREATE DATABASE <db_name>;
Create User
CREATE USER db_user WITH PASSWORD 'your-strong-password';
ALTER ROLE db_user SET client_encoding TO 'utf8';
ALTER ROLE db_user SET default_transaction_isolation TO 'read committed';
ALTER db_user SET timezone TO 'UTC';
Access user to create database (for django tests database).
ALTER USER db_user CREATEDB;
Connect user to the database
GRANT AL PRIVILEGES ON DATABASE db_name TO db_user;
Before project running, you must run tests to check project is work correctly. To run the tests, cd
into the directory where manage.py
is already exist:
python manage.py test
Once pipenv
or pip
has finished downloading the dependencies, Then simply apply the migrations:
python manage.py makemigrations
python manage.py migrate
You can now run the development server:
python manage.py runserver 8000
Finally navigate to http://localhost:8000