/drf-skel

Django rest framework skeleton project

Primary LanguageJavaScript

Django Rest Framework skeleton app

This project is setup to introduce some basic principles for setting up a web API project using the Django and Django Rest Framework frameworks.

Getting started

This project has been setup to include Docker and docker-compose to help with local development, along with a Makefile to wrap the docker commands up into easy to remember commands.

Once you have docker-compose setup and running locally, from your terminal simply run

make run

This will spin up a Django web server running on port 8080, along with a PostgreSQL database on port 5432.

For reference there is a single app running under the app/apps directory "foo" that you can visit. From your browser navigate to http://localhost:8080/foo.

Create local user

When you initially start the app, the database will be empty, including the users table. To create an admin account, with the app running, open a new terminal window and run:

make django-attach

Note if you have changed the name of the repo in your local environment, you will need to update DJANGO_CONTAINER variable in the Makefile at the root of the project to reflect the projects name

This is create a session within the running django container. Then to add a user simple run:

make createadmin

Installed packeages

Gloabl

pipenv Manages python packages in virutal environments (similar to virtualenv). This project installs all pipenv packages on the system level, negating the need for virtualisation (as docker handles that for us), but pipenv provides a more robust package management system that pip.

Django: Rapid development framework

djangorestframework: Rest API framework built onto of Django

psycopg2: Database driver for the PostgreSQL engine

json-logging: Logs are rendered in JSON format, for easier parsing by logging services, such as Cloudwatch and Datadog

black: Auto formatting of all python files

isort: Manages python import path ordering

Development

Markdown: For browserable API

Testing

pytest: Testing framework There are also a number of plugins for the pytest tool used:

  • pytest-django: Plugin for running the django test suite via pytest
  • pytest-cov: Plugin for providing test coverage statistics
  • pytest-flakes: Plugin for checking for linting errors based on the flakes defination
  • pytest-pep8: Plugin for checking for linting errors based on the pep8 defination
  • pytest-mccabe: Plugin for checking cyclomatic complexity of the python files