By NdibeRaymond
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!
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:
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)
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.
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.
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.
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.
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.
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!
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.