antoniovmonge / drf-apis

Django REST framework application

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Django REST framework application

Django REST framework application.

Built with Cookiecutter Django Black code style

License: MIT

Build the Stack

  1. Install pre-commit locally
pip install pre-commit
  1. Build the image
docker-compose -f local.yml build
  1. Initialize Git
git init
  1. Run the Pre-commit command to install it on the project
pre-commit install

Remove all

docker system prune --volumes -a -f
docker system prune -a -f

Build / Run the Image

docker-compose -f local.yml build
docker-compose -f local.yml up
docker-compose -f local.yml up --build

Set the default compose-file

export COMPOSE_FILE=local.yml

Execute Management Commands

docker-compose -f local.yml run --rm django python manage.py create_local_user_and_admin
docker-compose -f local.yml run --rm django python manage.py makemigrations (app)
docker-compose -f local.yml run --rm django python manage.py migrate
docker-compose -f local.yml run --rm django python manage.py createsuperuser
docker-compose -f local.yml run --rm django coverage run -m pytest

Change permission to be able to save/modified files or folder when access denied

sudo chown -R + "user" + "pwd"

Seed the database with Faker for develop

This command create fake books to seed the database.

docker-compose -f local.yml run --rm django python manage.py create_books

Settings

Moved to settings.

Basic Commands

Setting Up Your Users

  • To create a normal user account, just go to Sign Up and fill out the form. Once you submit it, you'll see a "Verify Your E-mail Address" page. Go to your console to see a simulated email verification message. Copy the link into your browser. Now the user's email should be verified and ready to go.

  • To create a superuser account, use this command:

docker-compose -f local.yml run --rm django python manage.py createsuperuser

For convenience, you can keep your normal user logged in on Chrome and your superuser logged in on Firefox (or similar), so that you can see how the site behaves for both kinds of users.

Type checks

Running type checks with mypy:

mypy drf_api

Test coverage

To run the tests, check your test coverage, and generate an HTML coverage report:

docker-compose -f local.yml run --rm django coverage run -m pytest
docker-compose -f local.yml run --rm django coverage html
docker-compose -f local.yml run --rm django open htmlcov/index.html

Running tests with unittest

docker-compose -f local.yml run --rm django python manage.py test

Running tests with pytest

docker-compose -f local.yml run --rm django pytest

Live reloading and Sass CSS compilation

Moved to Live reloading and SASS compilation.

Celery

This app comes with Celery.

To run a celery worker:

cd drf_api
celery -A config.celery_app worker -l info

Please note: For Celery's import magic to work, it is important where the celery commands are run. If you are in the same folder with manage.py, you should be right.

Email Server

In development, it is often nice to be able to see emails that are being sent from your application. For that reason local SMTP server MailHog with a web interface is available as docker container.

Container mailhog will start automatically when you will run all docker containers. Please check cookiecutter-django Docker documentation for more details how to start all containers.

With MailHog running, to view messages that are sent by your application, open your browser and go to http://127.0.0.1:8025

Sentry

Sentry is an error logging aggregator service. You can sign up for a free account at https://sentry.io/signup/?code=cookiecutter or download and host it yourself. The system is set up with reasonable defaults, including 404 logging and integration with the WSGI application.

You must set the DSN url in production.

Deployment

The following details how to deploy this application.

Docker

See detailed cookiecutter-django Docker documentation.

About

Django REST framework application

License:MIT License


Languages

Language:Python 69.4%Language:HTML 17.0%Language:Shell 7.0%Language:Dockerfile 6.3%Language:CSS 0.2%Language:JavaScript 0.0%