@blueprints-n-boilerplates/dj

This repository is intended as a cookiecutter for Django projects.

Technologies

You can choose to remove some technologies, whichever fits your project needs.

  1. Django 3.10.2 and Django REST
  • Backend framework used to create APIs, and is the main technology used in this repository.
  1. Sendgrid
  • Used for sending transactional emails.
  1. Twilio
  • Used for SMS--sending verification codes, in particular.
  1. Swagger UI
  • Visual documentation of available APIs.
  1. Docker
  • For containerizing apps.
  1. Pre-commit
  • Framework for managing and maintaining multi-language pre-commit hooks.
  1. Autoflake8
  • Tool to automatically fix some issues reported by flake8. A fork from autoflake and is used to remove unused imports and unused variables.
  1. Isort
  • Utility / Library to sort Python imports.
  1. Black
  • Uncompromising Python code formatter.
  1. TeleSign
  • For sending SMS, 2FA SMS.

First steps before running the app

  1. Create a virtual environment named venv
python3 -m venv venv
  1. Set environment variable values.

  2. Get inside the environment, upgrade pip and install the packages listed in requirements.

source venv/bin/activate
python -m pip install --upgrade pip
pip install -r requirements/development.txt
  1. Create environment file based on environment mode, and change the values.

For development mode, duplicate environment/dev.template.env and rename the duplicate file to environment/development.env. For staging mode, duplicate environment/staging.template.env and rename the duplicate file to environment/staging.env. For staging mode, duplicate environment/production.template.env and rename the duplicate file to environment/production.env.

  1. Up the server

If just using the terminal, run

python manage.py runserver

If using Pycharm IDE, refer docs/pycharm.md to read about creating Django server configurations.

  1. Run migrations
python manage.py migrate
  1. Create superuser
python manage.py createsuperuser
  1. Happy hacking!

Enabling pre-committing

Print sample config yaml file.

pre-commit sample-config > .pre-commit-config.yml

Install pre-commit

pre-commit install

Uninstall pre-commit

pre-commit uninstall

Running tests

python manage.py test --pattern="tests_*.py"
python manage.py test apps/services/"
python -m unittest test_file
python -m unittest test_sendgrid

1. Coverage

Code coverage testing for Python. It measures code coverage, typically during test execution. It uses the code analysis tools and tracing hooks provided in the Python standard library to determine which lines are executable, and which have been executed.

coverage run --omit='*/venv/*' manage.py test
coverage report  # get report
coverage html  # will generate an HTML report with a folder htmlcov/