Skip to content

tutorials-4newbies/learning_django

Repository files navigation

What is this

Technology

Django + drf + django-filter DB in postgresql Django configurations for settings file Common practice middlewares (timezones, querycount)

setup

Setup for development

  1. Python virtual environment:
    We are using poetry to manage the projects dependencies.
    Install Poetry - https://python-poetry.org/docs/#installation

  2. Get the code:
    Clone this project

    git clone still_missing
    
  3. Install dependencies:
    enter projects directory and install dependencies using Poetry. Poetry will look for pyproject.toml file

    cd learning_django
    poetry install
    

    And enter the virtual env created by Poetry:

    poetry shell
    

From this point in the setup you should run the commands while you are inside the virtual env / poetry shell


  1. Database:
    We are currently using postgres. You need to set up a user,

    • After you have installed postgres, enter postgres cli client:
    sudo su - postgres
    psql
    
    • create a database, a user and a role
    CREATE DATABASE learning_django_db;
    CREATE USER learning_django_user WITH PASSWORD 'learning_django_pass';
    ALTER ROLE learning_django_user SET client_encoding TO 'utf8';
    GRANT ALL PRIVILEGES ON DATABASE learning_django_db TO learning_django_user;
    ALTER ROLE learning_django_user CREATEDB;
    
    • If PostgreSQL version is 15+
    \c learning_django_db
    GRANT ALL ON SCHEMA public TO learning_django_user;
    
    • to exit postgres cli:
      Ctrl+D

      and then exit superuser shell
      exit

    • Now you can migrate the data:

    python manage.py migrate   
    
  2. Create a superuser for yourself to start working

    python manage.py createsuperuser 
    
  3. Run the dev server

    python manage.py runserver
    

tests

poetry run python manage.py test

Production

Ready to run as container (see dockerfile). Environment is determined by DJANGO_CONFIGURATION env variable which maps to class in settings.py. Note that in non local dev environments DEBUG=False so django won't magically serve statics You can use Nginx for that (before the django service, see, the nginx.conf for a reference) or install whitenoise and add it as a middleware. This is a common pattern for PAAS deployments

Setup for use in local environment as a "black box"

e.g when you work on the frontend

docker-compose up

First run would be quite long because of docker building

Postgres has some issues currently with start order, so if you see errors in the logs, just restart the compose a few times until it work

CI

Depends on where you run, we support an initial github actions CI out of the box -declared here and a full amazon environment with codebuild buildspec file

Not included libraries you might consider adding

Linting and formatting

With ruff, not automated yet as part of CI

ruff check . --fix
ruff format

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •