Question

App-Platform: Serve dockerized django (gunicorn server) on non-root url

Posted April 24, 2021 143 views
DjangoDigitalOcean App Platform

I recently deployed a dockerized Django app on DigitalOcean app platform along-side a react static site using the app spec file. Because of the static site, I opted to server django on a non-root URL (something like https://mydomain.com/api) and serve the react app on the root-url (https://mydomain.com).

If I visit the django URL, django comes up but throws a “path not found error”. The solution doesn’t see to be on google either and I don’t know why.

here is what my app.yaml looks like

name: test
region: nyc
services:
  - name: backend-api
    github:
      branch: deployment_app_platform
      repo: NdibeRaymond/test
      deploy_on_push: true

    http_port: 8000
    instance_count: 1
    instance_size_slug: basic-xxs
    source_dir: backend/
    dockerfile_path: backend/compose/django/Dockerfile
    routes:
      - path: /api

static_sites:
  - name: frontend
    environment_slug: node-js
    github:
      branch: deployment_app_platform
      repo: NdibeRaymond/test
      deploy_on_push: true

    source_dir: frontend/test/
    build_command: npm run build
    routes:
      - path: /


gunicorn configuration

exec /usr/local/bin/gunicorn test.wsgi --threads=3 --bind 0.0.0.0:8000 --chdir /backend/test

root URL file

urlpatterns = [
    path('admin/', admin.site.urls),
    path('api-auth/', include('rest_framework.urls')),
    path('summernote/', include('django_summernote.urls')),
    path('', include('APIS.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

I also tried

urlpatterns = [
    path('api/admin/', admin.site.urls),
    path('api/api-auth/', include('rest_framework.urls')),
    path('api/summernote/', include('django_summernote.urls')),
    path('api/', include('APIS.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Submit an answer

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!