[Answered ]-How to use Django/Nodejs with DDEV

1👍

For a quick and dirty answer on django, I’d like to get you started with a simple and probably inadequate approach, but it shows how easy it is to add something like django. We’ll just use the django dev server.

  1. Make a directory, I called mine dj and cd dj
  2. ddev config --auto
  3. Add to the .ddev/config.yaml:
webimage_extra_packages: [python3-django]
hooks:
  post-start:
    - exec: python3 manage.py runserver 0.0.0.0:8000
  1. Add .ddev/docker-compose.django.yaml:
version: "3.6"
services:
  web:
    expose:
      - 8000
    environment:
      - HTTP_EXPOSE=80:8000
      - HTTPS_EXPOSE=443:8000
    healthcheck:
      test: "true"
  1. ddev start
  2. ddev ssh and create a trivial django project:
  3. django-admin startproject dj .
  4. Add to your dj/settings.py ALLOWED_HOSTS = ["dj.ddev.site"]
  5. Exit back out to the host with ctrl-D or exit and ddev start
  6. You should be able to access the trivial project at https://dj.ddev.site

Note that as you proceed, you’ll probably want to end up starting the django server another way, or more likely actually front it by the ddev-webserver nginx server, which would be more natural (as in https://docs.nginx.com/nginx/admin-guide/web-server/app-gateway-uwsgi-django/). But for now, this is a simple demonstration. Happy to help you as you go along.

👤rfay

Leave a comment