Coder Social home page Coder Social logo

oryon-dominik / skeleton-django-postgres-docker Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 265 KB

providing a basic django structure to start your projects with a dockerized CRUD app and postgres

Python 73.94% HTML 13.68% Jupyter Notebook 1.36% CSS 0.06% Dockerfile 3.79% Shell 7.17%

skeleton-django-postgres-docker's Introduction

README

Installation

The repository setup.

  1. Use this repo as a template for your own, then clone it git clone <repository-address> <target>.
  2. Setup name & description in pyproject.toml. If you're using vscode (like me) rename and customize the skeleton.code-workspace to suit your needs.
  3. Create a dotenv touch ./.envs/.production.env where the projects environment variables will get set to. (you may use the example cp ./.envs/.production.example.env ./.envs/.production.env).
  4. For dependency-management I use poetry. If poetry is installed, install the dependencies with poetry install.
  5. Activate the venv just created with poetry shell or workon <venv-name> (I recommend using virtualenvwrapper).

The django-part, using docker-containers.

After you've built the containers with a docker compose build you can exec all neccessary commands.

docker compose run django <command>

Commands:

  1. Create migrations for your models python manage.py makemigrations (repeat this anytime you change your models).
  2. Apply the migrations to the database python manage.py migrate.
  3. If you need an adminuser also create it with python manage.py createsuperuser.

We can use notebooks for an easy access to an interactive django-shell. (To debug, develop or create model-instances on the fly)

docker compose up exposes the application server on localhost:8000 and a notebook on localhost:8888.

Happy coding =)

Management Commands

I'm aliasing python commands.py -> cc to call management commands in all my projects.
It's a CLI interface using the python library typer. All available commands are defined in commands.py
(Trivia: I'm never aliasing gcc or any other c-compilers to cc, so: no conflicts here).

cc up: start all containers.
cc rebuild: re-build the containers. Neccessary, if you added a package via poetry.
cc shell: if the server is already running, you can debug your application in a django-db-shell. from apps.users.models import User; User.objects.all()

There are also some abbreviations available. cc mmm: makemigrations & migrate.

Look up all other control-commands for the project via cc --help or glimpse into the commands.py yourself.

Example implementation of the cc <command> alias in a powershell script:

function cc () {
    $commands = ".\commands.py"
    $cwd = (Get-Location)
    $parent = Split-Path -Path $cwd
    if (Test-Path $commands -PathType leaf) {
        python commands.py $args
    }
    elseif (Test-Path (Join-Path -Path $parent -ChildPath $commands) -PathType leaf) {
        Set-Location $parent
        python commands.py $args
        Set-Location $cwd
    }
    else {
        Write-Host "commands.py not found" 
    }
}

other skeletons

django minimal sqlite
django with postgres & docker (this repo)
fastAPI

skeleton-django-postgres-docker's People

Contributors

oryon-dominik avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.