Report this

What is the reason for this report?

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

Posted on April 24, 2021

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)



This textbox defaults to using Markdown to format your answer.

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

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Heya,

The error message you’re receiving, “path not found,” is quite generic. It could be related to various issues. To diagnose and fix the issue, consider the following steps:

  1. Check Django’s configuration: Ensure that your Django application is configured to run under the “/api” path. It appears that you have attempted this by modifying the urlpatterns in your Django app, which is a step in the right direction.

Here’s the recommended way to set the urlpatterns in Django for serving the app under “/api”:

from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    path('admin/', admin.site.urls),
    path('api-auth/', include('rest_framework.urls')),
    path('summernote/', include('django_summernote.urls')),
    path('api/', include('APIS.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
  1. Dockerfile Configuration: Verify that your Dockerfile for Django is correctly configured to serve the application under the desired path. Ensure that the Django application is being run with the correct settings and URL path.

  2. Routing Configuration: Double-check your App Spec file. It appears that you’ve configured the React app to be served at the root path with "path: /". Make sure that you haven’t inadvertently changed this configuration.

  3. Debugging and Logs: App Platform provides logs that can be helpful for diagnosing issues. Check the logs for any error messages that can provide more specific information about what might be going wrong.

  4. Testing Locally: To isolate the issue, you can try running your Dockerized Django app locally and configuring it to run under the “/api” path. This can help you confirm that the Django app works as expected under that path.

  5. Reverse Proxy (if applicable): If you are using a reverse proxy, make sure it’s configured correctly to forward requests to the Dockerized Django app at the “/api” path.

  6. Caching or Browser Issues: Sometimes, caching or issues with the browser can cause problems. Try accessing the URL in an incognito window or clearing your browser cache to ensure you’re not seeing cached content.

If you’ve verified all the above points and are still facing the issue, check the specific error message and logs for more details. If you can provide more information about the error message or any specific error codes, it will be easier to further troubleshoot the problem.

Hope that this helps!

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.